g ++ undefined对`boost :: system :: system_category()'的引用

Cra*_*aig 16 linker boost compiler-errors g++

我已经搜索了这个问题的答案.我正在使用boost 1.48并且该程序非常简单,因为我已将其分解为最简单的形式以解决此问题.

#include <boost/filesystem.hpp>

int main(int argc, char **argv) {
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

从我的Makefile执行的g ++命令如下:

g++ -m32 -Wall -o mapnik-test -L/usr/lib -I/usr/include -I/usr/include/freetype2 -lpthread -lboost_system mapnik-test.cpp
Run Code Online (Sandbox Code Playgroud)

链接期间的完整错误列表如下:

/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
Run Code Online (Sandbox Code Playgroud)

我发现很多人都遇到了同样的问题,但在大多数情况下,解决方案是在LDFLAGS中提供boost_system库.从g ++命令行可以看出,我已经指定了这个.我甚至尝试显式链接libboost_system.a库无济于事.我是这个投诉的唯一人吗?

pan*_*kal 26

将源文件放在命令行的开头.

尝试

g++ -m32 -Wall mapnik-test.cpp -o mapnik-test -L/usr/lib -I/usr/include -I/usr/include/freetype2 -lpthread -lboost_system
Run Code Online (Sandbox Code Playgroud)

应仅在源文件之后指定库,以便链接器可以解析源文件中的未定义引用.