开发者

Linking static library with gnu g++, No such file or directory

I'm writing a software that depends on the Poco c++ library. I can manage to compile the library on both Ubuntu and Windows, but only as static. That's fine since I want to use it statically. However, when I try to compile the program that depends on the libraries, I get an error similar to this (freely translated) :

Poco/RegularExpression.h: No such file or directory.

However, when I also explicitly tells the compiler where to look for the library's header files with the -I switch I get the following error instead (but maybe 20-30 similar lines) :

Undefined reference to (pthread_mutex...)

I've tried with a lot of different combinations, both directly with g++, and by using makefiles. Am I supposed to include the paths to the 开发者_开发技巧libraries' header files, or have I somehow not succeeded to compile the libraries properly? If I should include the paths, how can I get rid of the "undefined reference" error?

I'm pretty new with c++ programming so bear with me. Thanks, Robert


This is very common error, I, too, suffer from it every now and then.

  • Did you include the .a to your project?
  • How do you include the headers? with <> or ""?
    • If the latter, make sure the files are in your include folder.
    • If first, make sure you have added the path to the files, or that they reside in g++'s global include folder
  • Is the library meant to be compiled as .so/.dll?
    • Normally if the library is meant to be dynamic, the static library only points to it.
  • Do you have included the dependencies the Poco itself requires? Like the -lpthread I think you are missing.


Try the -I option. In the target that has RegularExpression.h as a dependancy, try to include the directory that contains the above header file like so:

g++ -I/home/.../Poco <other options>

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜