boost - g++ 对 `boost::system::system_category()' 的 undefined reference

标签 boost linker compiler-errors g++

我已经搜索了很多关于这个问题的答案。我使用的是 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/

相关文章:

c++ - Boost 图的自定义 InputIterator (BGL)

c - Xcode 错误 : "Undefined symbols for architecture x86_64: "_addStudent", 从 : _main in main. o 引用

qt - QVision Widget 编译时出错

boost - 让 Macports 为 iOS 和 OS X 编译 Boost

c++ - 将 boost::shared_ptr 与 WSACleanup 结合使用

c - ld-linux.so 执行 CTOR 的顺序?

c - 如何强制链接器将字符串数组的 const 数组存储到闪存中(而不是 RAM)

objective-c - 使用未声明的标识符

c# - IntPtr.operator +(IntPtr,int)无法调用运算符或访问器

python - 将 CMakeLists.txt、boost-python 与 python setuptools 相结合