为什么 CMake 在 Ubuntu 18.04 上找不到我的 Boost 库?
Why CMake cannot find my Boost libraries on Ubuntu 18.04?
这让我抓狂。在我的 CMakeLists.txt
中,我有:
find_package(Boost 1.63.0 REQUIRED SYSTEM)
结果:
[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/local/include
的文件都删掉了。也许它仍然以某种方式困扰着这里..?
如果我找到像这样的 Boost(没有系统):
find_package(Boost 1.63.0 REQUIRED)
..然后配置成功,但不会 link 到 ${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
,即使它在使用 SYSTEM
时也抱怨缺少 boost_system
。我发现 位 令人困惑:
find_package(Boost 1.63.0 REQUIRED system)
这让我抓狂。在我的 CMakeLists.txt
中,我有:
find_package(Boost 1.63.0 REQUIRED SYSTEM)
结果:
[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/local/include
的文件都删掉了。也许它仍然以某种方式困扰着这里..?
如果我找到像这样的 Boost(没有系统):
find_package(Boost 1.63.0 REQUIRED)
..然后配置成功,但不会 link 到 ${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
,即使它在使用 SYSTEM
时也抱怨缺少 boost_system
。我发现 位 令人困惑:
find_package(Boost 1.63.0 REQUIRED system)