在将我的 C++ 项目与外部库(例如 Boost、wxWidgets、Gtkmm)链接起来时,我时常遇到困难。有没有办法将这些外部库合并到编译器(在我的例子中是 GNU G++,winXP SP3),以便编译器可以像使用 C++ STL 一样将它们作为它的一部分?
最佳答案
与库链接(以 Boost Libs 和 g++ 编译器为例):
使用正确的包含文件编译源代码
1) g++ -I/path/to/boost_dir -c 代码.cpp
2) g++ -L/path/to/your/boost/shared/libs -lboost_regex -o 可执行代码.o
对于链接部分,我以 boost 正则表达式库为例
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.
关于c++ - 外部 C++ 库链接问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6928706/