我已经搜索了很多关于这个问题的答案。我使用的是 boost 1.48 并且程序非常简单,因为我已将其分解为最简单的形式以解决此问题。
#include <boost/filesystem.hpp>
int main(int argc, char **argv) {
return 0;
}
从我的 Makefile 执行的 g++ 命令如下:
g++ -m32 -Wall -o mapnik-test -L/usr/lib -I/usr/include -I/usr/include/freetype2 -lpthread -lboost_system mapnik-test.cpp
链接期间的完整错误列表如下:
/tmp/ccIbmuee.o: In function `__static_initialization_and_destruction_0(int, int)':
mapnik-test.cpp:(.text+0x49): undefined reference to `boost::system::generic_category()'
mapnik-test.cpp:(.text+0x53): undefined reference to `boost::system::generic_category()'
mapnik-test.cpp:(.text+0x5d): undefined reference to `boost::system::system_category()'
collect2: ld returned 1 exit status
make: *** [mapnik-test] Error 1
我发现很多人都遇到了同样的问题,但在大多数情况下,解决方案是在 LDFLAGS 中提供 boost_system 库。从 g++ 命令行可以看出,我已经指定了这个。我什至尝试过明确链接 libboost_system.a 库,但无济于事。我是唯一提出此投诉的人吗?
最佳答案
将源文件放在命令行的开头。
尝试
g++ -m32 -Wall mapnik-test.cpp -o mapnik-test -L/usr/lib -I/usr/include -I/usr/include/freetype2 -lpthread -lboost_system
应仅在源文件之后指定库,以便链接器可以解析源文件中 undefined reference 。
关于boost - g++ 对 `boost::system::system_category()' 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11250144/