开发者

External C++ Libraries Linking Problems

I have been facing difficulties, now and then, linking my C++ projects with external libraries (e.g. Boost, wxWidgets, Gtkmm). Is there a way to incorporat开发者_运维知识库e these external libraries into the compiler (GNU G++ in my case, winXP SP3) so that the compiler can take them as part of it just like with C++ STL?


To link with a library (Taking example of Boost Libs and g++ compiler):

Compiling the source with correct include files

1) g++ -I /path/to/boost_dir -c code.cpp

2) g++ -L/path/to/your/boost/shared/libs -lboost_regex -o executable code.o

For the linking part I have taken example of boost regex library

A full example ::
1) Consider your boost directory is at /usr/include/boost.
2)within this we have multiple header files and directories, So if you want to use the lambda functionality of boost, then include it in your code as below::

#include< boost/lambda.hpp >
#include< boost/regex >
using namespace boost::lambda;

3) Compile as "g++ -I /usr/include -c code.cpp"
Then 
4) g++ -L /usr/lib -lboost_regex -o executable code.o

I have assumed that the boost shared objects are present at /usr/lib path.


As far as I know the way to do that is telling the compiler where to search for libraries (-L) and what their names are (-l).

But I'm not a gcc expert and I'm unaware of ways to hack/configure the compiler to always assume they have to link to certain libraries besides C standard library and STL (when using g++).

Would be nice to know if you can do that (and how) because, well, knowledge is power :)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜