在Cygwin上链接Boost库
Linking Boost library on Cygwin
我已经在这里待了几个小时了,所以我来这里寻求帮助。 很确定我几乎已经弄清楚了,但我继续遇到对boost::system::generic_category
和boost::system::system_category
的未定义引用的链接器错误。
我只有一个文件正在尝试链接以制作可执行文件。
我从编译它开始制作一个对象文件:
g++ -c main.cpp -I C:/boost/boost_1_61_0
这将成功创建 main.o。
我的下一个也是最后一个目标是将其链接到可执行文件。我尝试了与在其他帖子上阅读的不同的东西:
g++ main.o -L C:/boost/boost_1_61_0/stage/lib
g++ main.o -L C:/boost/boost_1_61_0/stage/lib/libboost_system.a
g++ main.o -lboost_system
结果要么告诉我它找不到库,要么类似:
main.o:main.cpp:(.text+0x89): undefined reference to `boost::system::generic_category()'
main.o:main.cpp:(.text+0x89): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::system::generic_category()'
main.o:main.cpp:(.text+0x95): undefined reference to `boost::system::generic_category()'
main.o:main.cpp:(.text+0x95): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::system::generic_category()'
main.o:main.cpp:(.text+0xa1): undefined reference to `boost::system::system_category()'
main.o:main.cpp:(.text+0xa1): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::system::system_category()'
main.o:main.cpp:(.text$_ZN5boost11this_thread9sleep_forERKNS_6chrono8durationIlNS_5ratioILl1ELl1000000000EEEEE[_ZN5boost11this_thread9sleep_forERKNS_6chrono8durationIlNS_5ratioILl1ELl1000000000EEEEE]+0x24): undefined reference to `boost::this_thread::hiden::sleep_for(timespec const&)'
main.o:main.cpp:(.text$_ZN5boost11this_thread9sleep_forERKNS_6chrono8durationIlNS_5ratioILl1ELl1000000000EEEEE[_ZN5boost11this_thread9sleep_forERKNS_6chrono8durationIlNS_5ratioILl1ELl1000000000EEEEE]+0x24): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `boost::this_thread::hiden::sleep_for(timespec const&)'
collect2: error: ld returned 1 exit status
我知道我正确地构建了 boost 库,因为在 stage/lib 目录中的许多其他库中都有一个 libboost_system.a 文件。有什么想法吗?
让我们从您尝试过的命令开始。
g++ main.o -L C:/boost/boost_1_61_0/stage/lib
这会告诉g++
在C:/boost/boost_1_61_0/stage/lib
目录中查找库。它没有说要拉入哪些库,但是一旦你这样做了,g++
就会在那里看。
由于您的代码具有对boost_system
中找到的内容(如boost::system::generic_category
(的引用,并且由于您没有告诉链接器拉入该库,因此这些引用最终未定义。
g++ main.o -L C:/boost/boost_1_61_0/stage/lib/libboost_system.a
这会告诉g++
在C:/boost/boost_1_61_0/stage/lib/libboost_system.a
目录中查找库。由于这(大概(不是一个目录,因此-L
标志没有实际效果。
g++ main.o -lboost_system
这会告诉g++
在boost_system
库中链接。虽然链接器知道如何转换库名称(例如boost_system
( 到相应的文件名(例如libboost_system.a
(,没有指示在哪里可以找到此文件。因此,链接器将查找它知道的默认目录。当在那里找不到文件时,g++
抱怨找不到库。
此时,您应该看到需要组合的两个部分:告诉链接器要拉入哪个库以及在哪里找到它。
g++ main.o -lboost_system -L C:/boost/boost_1_61_0/stage/lib
- 基于boost的程序的静态链接——zlib问题
- 在Cygwin上链接Boost库
- CMAKE中无法链接Boost
- 使用cmake错误链接boost日志
- 程序使用boost::文件系统链接clang,但不使用gcc
- 编译时出现Boost.python链接错误
- 链接问题 boost::p ython::numpy.
- 将 boost 与 Visual Studio 和 vcpkg 链接时出错
- 如何在 Oracle Linux 上的 Eclipse 中编译和链接 boost 库
- 使用 BOOST property_tree / iostreams / 文件系统 / foreach - 结果出现链接
- 链接 boost 库时"Error while loading shared libraries"引发的,除了我无法使用 root 访问权限来修复它
- boost::存在符号链接不取消引用
- Android Studio 链接器命令在包含 Boost 库时失败
- 如何链接到与 Linux 中不同版本的 boost 链接的共享库
- boost/filesystem.hpp未通过Homebrew安装的OSX Boost链接
- Boost:链接由bjam命名的库时出现致命错误LNK1104
- Boost链接错误-单个未定义的引用
- 使用仅头文件库时,Boost链接器错误
- dev - c++中Boost链接/构建的问题
- 我应该使用哪些编译选项来使用cl.exe与Boost链接