2

I'm using CMake 3.8.2 and a custom build Boost 1.64 on travis. I set BOOST_ROOT CMake variable to the prefix where I installed boost. However it still keeps picking the wrong libraries (system installed ones) although it finds my headers.

I tried to debug everything I could but failed to find the reason. Any Ideas why CMake picks the wrong libs?

From 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

Looking into FindBoost of CMake 3.8.2 it leads to find_library to be ultimately called like:

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}"
    )

If this finds /usr/local/lib/libboost_filesystem-mt.a it HAS TO find my custom library which is in the first HINTS option and NAMES_PER_DIR is specified. I double-checked CMAKE_PREFIX_PATH, CMAKE_LIBRARY_PATH and CMAKE_FRAMEWORK_PATH and all are empty.

So what is happening here?

To clarify the difference to e.g. How can I get CMake to find my alternative Boost installation?:

  • I'm using cmake .... -DBOOST_ROOT=$BOOST_DIR
  • It does find the headers and is not using e.g. the Boost.CMake module
  • It has "my" path first in the HINTS of find_library and NAMES_PER_DIR should mean it finds my libs first, but it does not.
Flamefire
  • 5,313
  • 3
  • 35
  • 70
  • Why is this a duplicate? In the linked question `-DBOOST_ROOT` was not set, but here it is. – Flamefire Jan 08 '19 at 10:08
  • You mean you invoke it as `cmake -DBOOST_ROOT=`? – StoryTeller - Unslander Monica Jan 08 '19 at 10:12
  • Yes. See 2nd sentence in the question. The output below shows, that it actually does find that but only the headers and `find_library` then does something which seems to violate its documentation – Flamefire Jan 08 '19 at 10:13
  • Don't be rude and tell me to see the 2nd sentence. Write explicit examples to demonstrate. You claim you set it, then you show `ls -la "${BOOST_DIR}/lib"` which can mean you assumed it has to be an environment variable. – StoryTeller - Unslander Monica Jan 08 '19 at 10:14
  • Sorry, I didn't mean to be rude. I just wanted to refer to "I set `BOOST_ROOT` CMake variable". I also added explicit clarification at the bottom of the question. I hope this helps – Flamefire Jan 08 '19 at 10:18
  • Can you *manually* (i.e. no cmake) link a simple program with the desired libraries? – n. m. could be an AI Jan 08 '19 at 10:28
  • Your installation also doesn't have the static library which cmake ultimately picks. Did you perhaps configure your project for static linking? – n. m. could be an AI Jan 08 '19 at 10:40
  • 1
    @Flamefire Recently only I faced similar issue. I had to specify: `-DBoost_NO_BOOST_CMAKE=ON` to disable the system Boost Libraries as mentioned in the [link](https://stackoverflow.com/questions/3016448/how-can-i-get-cmake-to-find-my-alternative-boost-installation) provided by you in the question. – AmeyaVS Jan 08 '19 at 10:45
  • 1
    @n.m. You are correct. It seems that Boost for some reason only builds **some** libraries static. I got mislead by e.g. the static boost_system. It is probably a good idea to use `-DBoost_NO_SYSTEM_PATHS=ON` to ensure the system boost is not used. If you want to make that an answer, I'll accept. `-DBoost_NO_BOOST_CMAKE=ON` is **not** the important one here (it would result in different output showing that a cmake config file is used, which is not the case here) – Flamefire Jan 08 '19 at 11:42

0 Answers0