c++ - 为什么 CMake 在 Ubuntu 18.04 上找不到我的 Boost 库?

标签 c++ linux boost cmake ubuntu-18.04

这让我抓狂。在我的 CMakeLists.txt 中,我有:

find_package(Boost 1.63.0 需要系统)

结果:


[0/1] Re-running CMake...
Build type: Release
CMake Error at /usr/share/cmake-3.10/Modules/FindBoost.cmake:1947 (message):
  Unable to find the requested Boost libraries.

  Boost version: 1.65.1

  Boost include path: /usr/include

  Could not find the following Boost libraries:

          boost_system

但是:

$ locate libboost_system
/usr/lib/x86_64-linux-gnu/libboost_system.a
/usr/lib/x86_64-linux-gnu/libboost_system.so
/usr/lib/x86_64-linux-gnu/libboost_system.so.1.65.1

和:

$ sudo apt install libboost-all-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
libboost-all-dev is already the newest version (1.65.1.0ubuntu1).

我之前用的是自己编译的1.63.0,但是我把/usr/local/lib/usr/里的文件都删掉了本地/包括。也许它仍然以某种方式出没于此……?

如果我发现这样的 Boost(没有系统):

find_package(需要 Boost 1.63.0)

..然后配置成功,但不会链接到${Boost_SYSTEM_LIBRARY}:

/usr/bin/ld: src/app/CMakeFiles/app.dir/application.cpp.o: undefined reference to symbol '_ZN5boost6system15system_categoryEv'
//usr/lib/x86_64-linux-gnu/libboost_system.so.1.65.1: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

最佳答案

问题是你应该要求 system而不是 SYSTEM即使它提示缺少 boost_system也当 SYSTEM被使用了。我发现这有点令人困惑:

find_package(Boost 1.63.0 REQUIRED system)

关于c++ - 为什么 CMake 在 Ubuntu 18.04 上找不到我的 Boost 库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58713393/

相关文章:

c++ - 转动相机后,形状倾斜 OpenGL

linux - 将所有以相同前缀开头的文件放在linux中的一个文件夹中

python - 从 Flask 中的另一个目录下载文件

linux - 在 VMWare 中捕获主机 IP

c++ - 链接器错误 - 带有 libboost_thread 的 macOS 上 undefined symbol std::string::c_str() const?

c++ - Visual Studio 2017 编译 DirectX8

c++ - 奇怪的功能查找

c++ - InitializeCriticalSectionEx 不在 KERNEL32.Dll 中

c++ - 在 Visual Studio 调试器中,{null=???} 是什么意思?

c++ - boost 线程问题