c++ - 外部 C++ 库链接问题

标签 c++ libraries

在将我的 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/

相关文章:

c++ - 为什么 C++ 不在同一行中实现构造 + 调用函数?

c++ - "Private Bytes"没有反射(reflect)它。如何找到进程分配的确切内存?

java - 在 clojure 中使用第三方 java 库,例如 com.jcraft.jsch

linux - 静态库的 Yocto 构建失败,错误为 "No Match Found"

c++ - 面向对象编程

c++ - 关于在 symbian 中使用 TCP/IP 写入

c++ - 如何打印 map 的索引?

python - 如何将 zip 和 targz 发行版上传到 PyPI?

c++ - 带有类的库如何工作?

C# 如何使用使用不同 CPU 架构的库?