g++出现undefined reference to `boost::system::system_category()'错误

16

我已经费尽心思地搜寻了关于这个问题的答案。我正在使用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库,但没有任何效果。难道只有我一个人会出现这种情况吗?

1个回答

27

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

尝试:

g++ -m32 -Wall mapnik-test.cpp -o mapnik-test -L/usr/lib -I/usr/include -I/usr/include/freetype2 -lpthread -lboost_system

库应该在源文件之后指定,这样链接器就可以解析源文件中的未定义引用。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接