我在travis上使用CMake 3.8.2和自定义构建Boost 1.64。我将BOOST_ROOT
CMake变量设置为安装boost的前缀。但是,尽管找到了我的头文件,它仍然继续选择错误的库(系统安装的库)。
我尝试调试所有可能的方法,但未能找到原因。知道为什么CMake选择错误的库吗?
来自https://travis-ci.com/Return-To-The-Roots/s25client/builds/96509387:
ls -la "${BOOST_DIR}/lib"
total 37952 drwxr-xr-x 17 travis staff 578 Jan 5 16:20 . drwxr-xr-x 4 travis staff 136 Jan 5 16:18 ..
-rw-r--r-- 1 travis staff 259576 Jan 7 18:20 libboost_chrono.a
-rwxr-xr-x 1 travis staff 18656 Jan 7 18:20 libboost_chrono.dylib
-rwxr-xr-x 1 travis staff 132152 Jan 7 18:19 libboost_filesystem.dylib
-rwxr-xr-x 1 travis staff 151976 Jan 7 18:19 libboost_iostreams.dylib
-rwxr-xr-x 1 travis staff 768636 Jan 7 18:19 libboost_locale.dylib
-rwxr-xr-x 1 travis staff 82192 Jan 7 18:20 libboost_prg_exec_monitor.dylib
-rwxr-xr-x 1 travis staff 572724 Jan 7 18:19 libboost_program_options.dylib
-rwxr-xr-x 1 travis staff 1243824 Jan 7 18:20 libboost_regex.dylib
-rw-r--r-- 1 travis staff 103008 Jan 7 18:20 libboost_system.a
-rwxr-xr-x 1 travis staff 24932 Jan 7 18:18 libboost_system.dylib
-rw-r--r-- 1 travis staff 14620656 Jan 7 18:21 libboost_test_exec_monitor.a
-rwxr-xr-x 1 travis staff 160108 Jan 7 18:20 libboost_thread.dylib
-rw-r--r-- 1 travis staff 285880 Jan 7 18:20 libboost_timer.a
-rwxr-xr-x 1 travis staff 48080 Jan 7 18:20 libboost_timer.dylib
-rwxr-xr-x 1 travis staff 925444 Jan 7 18:20 libboost_unit_test_framework.dylib
-- [ /Users/travis/build/Return-To-The-Roots/s25client/deps/cmakeosx/share/cmake-3.8/Modules/FindBoost.cmake:1171 ] _boost_INCLUDE_SEARCH_DIRS = /Users/travis/build/Return-To-The-Roots/s25client/deps/boost1.64.0/include;/Users/travis/build/Return-To-The-Roots/s25client/deps/boost1.64.0;PATHS;C:/boost/include;C:/boost;/sw/local/include
-- [ /Users/travis/build/Return-To-The-Roots/s25client/deps/cmakeosx/share/cmake-3.8/Modules/FindBoost.cmake:1421 ] _boost_LIBRARY_SEARCH_DIRS_RELEASE = /Users/travis/build/Return-To-The-Roots/s25client/deps/boost1.64.0/lib;/Users/travis/build/Return-To-The-Roots/s25client/deps/boost1.64.0/stage/lib;/Users/travis/build/Return-To-The-Roots/s25client/deps/boost1.64.0/include/lib;/Users/travis/build/Return-To-The-Roots/s25client/deps/boost1.64.0/include/../lib;/Users/travis/build/Return-To-The-Roots/s25client/deps/boost1.64.0/include/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib_boost_LIBRARY_SEARCH_DIRS_DEBUG
= /Users/travis/build/Return-To-The-Roots/s25client/deps/boost1.64.0/lib;/Users/travis/build/Return-To-The-Roots/s25client/deps/boost1.64.0/stage/lib;/Users/travis/build/Return-To-The-Roots/s25client/deps/boost1.64.0/include/lib;/Users/travis/build/Return-To-The-Roots/s25client/deps/boost1.64.0/include/../lib;/Users/travis/build/Return-To-The-Roots/s25client/deps/boost1.64.0/include/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib
-- [ /Users/travis/build/Return-To-The-Roots/s25client/deps/cmakeosx/share/cmake-3.8/Modules/FindBoost.cmake:1567 ] Searching for FILESYSTEM_LIBRARY_RELEASE: boost_filesystem-mt-1_64;boost_filesystem-mt;boost_filesystem
-- [ /Users/travis/build/Return-To-The-Roots/s25client/deps/cmakeosx/share/cmake-3.8/Modules/FindBoost.cmake:365 ] Boost_LIBRARY_DIR_RELEASE = /usr/local/lib
_boost_LIBRARY_SEARCH_DIRS_RELEASE = /usr/local/lib;NO_DEFAULT_PATH;NO_CMAKE_FIND_ROOT_PATH
Boost_FILESYSTEM_LIBRARY_DEBUG:FILEPATH=/usr/local/lib/libboost_filesystem-mt.a
查看CMake 3.8.2的FindBoost会导致find_library
最终被调用为:
find_library(result_var
NAMES boost_filesystem-mt-1_64;boost_filesystem-mt;boost_filesystem
HINTS /Users/travis/build/Return-To-The-Roots/s25client/deps/boost1.64.0/lib;<more paths>
NAMES_PER_DIR
DOC "${_boost_docstring_release}"
)
如果找到/usr/local/lib/libboost_filesystem-mt.a
,则必须找到我的自定义库,该库位于第一个HINTS选项中,并指定了NAMES_PER_DIR。我仔细检查了CMAKE_PREFIX_PATH,CMAKE_LIBRARY_PATH和CMAKE_FRAMEWORK_PATH,它们都是空的。
那么这是怎么回事?
阐明与How can I get CMake to find my alternative Boost installation?:
cmake .... -DBOOST_ROOT=$BOOST_DIR
find_library
的提示中首先具有“我的”路径,而NAMES_PER_DIR
则意味着它首先找到了我的库,但是没有找到。