外部 C++库链接问题
在将我的 C++ 项目与外部库(例如 Boost、wxWidgets、Gtkmm)链接时,我时常遇到困难。有没有办法将这些外部库合并到编译器中(在我的例子中是 GNU G++,winXP SP3),以便编译器可以将它们作为其一部分,就像使用 C++ STL 一样?
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 incorporate 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
链接库(以 Boost Libs 和 g++ 编译器为例):
使用正确的包含文件编译源代码
1) g++ -I /path/to/boost_dir -c code.cpp
2) g++ -L/path/to/your/boost/shared/libs -lboost_regex -o 可执行代码.o
对于链接部分,我以 boost 正则表达式库为例
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
据我所知,这样做的方法是告诉编译器在哪里搜索库(-L)以及它们的名称是什么(-l)。
但我不是 gcc 专家,我不知道如何破解/配置编译器,以始终假设它们必须链接到除 C 标准库和 STL 之外的某些库(使用 g++ 时)。
很高兴知道您是否可以做到这一点(以及如何做到),因为知识就是力量:)
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 :)