开发者

Why isn't my include directive working in gcc?

I'm working on some code that uses Open Dynamics Engine. I've worked with this code before on windows, but now I'm moving over to unix so I can get experience working with C under a unix environment and so I'm not reliant on visual studio. I downloaded everything to my home directory, built using the included makefile and tried a demo; everything's good. I made a directory and a test file in it with my own test. For my #include I specified:

#include ".././ode-0.11.1/include/ode/ode.h"
#include ".././ode-0.11.1/include/drawstuff/drawstuff.h"

Since the library is just located in my home directory and not in the standard location. I go to compile my code but:

.././ode-0.11.1/include/ode/ode.h:28:27: fatal error: ode/odeconfig.h: No such 
file or directory

Looking at ode.h, it includes a bunch of other headers all located in the same directory, but using the bracket syntax instead of quotes. I'm guessing this has something to do with why gcc can't locate the other headers. I've looked at the makefiles but don't know enough to figure out what my issue is. Why is my compilation not working? A detailed/thorough answer would be appreciated since I want to learn how this all works (linking, includes, make, etc.).

Edit: So I figured out how to include the headers correctly, now I need to figure out how to link to the library definitions for the functions...

Edit2: Still can't figure out how to link to my code. The compiled static libraries get dumped in '~/ode-0.11.1/ode/src/.libs' and '~/ode-0.11.1/drawstuff/src/.libs' for the drawing functions.

Edit3: I think I figured it out. I wasn't using the -l option correctly, and it seems like it has to go AFTER the files that reference functions from the librar开发者_Python百科ies I'm linking to.


You need to set the include directory in the compile line

e.g.

gcc -I.././ode-0.11.1/include

or better in this cas an absolute path

Then in code include like

#include "ode/ode.h"
#include "drawstuff/drawstuff.h"

Thus all the files included from ode.h will be accessed from the same directory. Your example ode/odeconfig.h would be found as ode is a subdirectoy from the include path in the -I parameter.

Linking is similar but both parts done on the command line .The two parts are file given by a -l variable and the directory the lib is in by -L parameter. Also if the library is say libode.dylib the you just meed the name e.g. ode.

So command line is

gcc -lode -L.././ode-0.11.1/lib


go to directory ode-0.11.1 This will be the project's home.

So include files belong to directory ode-0.11.1/include In this case your source should be like

myprog.c

#include "ode/ode.h"
#include "drawstuff/drawstuff.h"

compilation command should be a line like:

gcc -I./include/ode -I./include/drawstuff  myprog.c -o myprog

Command executed in directory ode-0.11.1/include

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜