Cmake cannot find Boost libraries
Your configuration looks a bit weird and dirty. Especially things like:
ADD_DEFINITIONS(-DBoost_USE_STATIC_LIBS=ON)
It's not a C/C++ preprocessor definition! It's a CMake variable which is used to control how CMake will define the linkage stage of your project with Boost libraries.
If you properly compiled Boost and didn't mess up anything, then the directory structure usually looks like this:
<boost-dir>
include
boost
accumulators
...
aligned_storage.hpp
...
lib
libboost_atomic-mt-s.a
...
NOTE: The root directory of Boost, <boost-dir>
, appears to be D:/boost_1_54_0
in your case.
If in your case it does not look like above, then I'd suggest to rearrange it manually to the one above since, once again, this is how it should be.
When done, let's do some CMake configuration. I suggest to keep things simple and clean in the first place, and obey the CMake conventions. Test the following:
set(BOOST_INCLUDEDIR D:/boost_1_54_0/include)
set(BOOST_LIBRARYDIR D:/boost_1_54_0/lib)
NOTE: You can find thorough description of both of these variables at the top of FindBoost.cmake
.
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
NOTE: This is how you enforce static linkage by setting the CMake variable properly, but not like you did by setting a non-existent C/C++ preprocessor definition.
find_package(Boost
1.54.0
COMPONENTS thread
system
log
log_setup
program_options
REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(<target_name> ${Boost_LIBRARIES})
NOTE: Instead of <target_name>
, put the name of the target that you wish to build (executable, static/shared library, etc.).
user1382494
Updated on July 22, 2020Comments
-
user1382494 almost 4 years
I am new to Cmake and boost libraries in C++. I am working on a project that needs boost and Cmake. I am using Cmake version 2.8.11, MS Visual Studio 2013 and Boost 1.54.0. When I try to configure from Cmake, it is giving the following error:
CMake Error at C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:1106 (message): Unable to find the requested Boost libraries. Boost version: 1.54.0 Boost include path: D:/boost_1_54_0 The following Boost libraries could not be found: boost_thread boost_system boost_log boost_log_setup boost_program_options No Boost libraries were found. You may need to set BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT to the location of Boost. Call Stack (most recent call first): CMakeLists.txt:20 (find_package)
I have seen quite a few questions related to mine and tried, but all went in vain. My Cmakelists.txt file looks like this:
################################ # Boost ################################ ADD_DEFINITIONS(-DBOOST_LOG_DYN_LINK) ADD_DEFINITIONS(-DBoost_USE_STATIC_LIBS=ON) set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS ON) set(Boost_INCLUDE_DIR D:/boost_1_54_0) set(Boost_LIBRARY_DIR D:/boost_1_54_0/stage/lib) find_package( Boost 1.54.0 REQUIRED thread system log log_setup program_options) find_package( Threads ) INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} ) LINK_DIRECTORIES(${Boost_LIBRARY_DIR})
The CMake output after setting Boost_DEBUG ON is as follows:
[ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:476 ] _boost_TEST_VERSIONS = 1.56.0;1.56;1.55.0;1.55;1.54.0;1.54 [ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:478 ] Boost_USE_MULTITHREADED = TRUE [ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:480 ] Boost_USE_STATIC_LIBS = TRUE [ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:482 ] Boost_USE_STATIC_RUNTIME = [ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:484 ] Boost_ADDITIONAL_VERSIONS = [ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:486 ] Boost_NO_SYSTEM_PATHS = [ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:538 ] Declared as CMake or Environmental Variables: [ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:540 ] BOOST_ROOT = D:/boost_1_54_0 [ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:542 ] BOOST_INCLUDEDIR = [ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:544 ] BOOST_LIBRARYDIR = [ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:546 ] _boost_TEST_VERSIONS = 1.56.0;1.56;1.55.0;1.55;1.54.0;1.54 [ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:615 ] Include debugging info: [ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:617 ] _boost_INCLUDE_SEARCH_DIRS = D:/boost_1_54_0/include;D:/boost_1_54_0;PATHS;C:/boost/include;C:/boost;/sw/local/include [ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:619 ] _boost_PATH_SUFFIXES = boost-1_56_0;boost_1_56_0;boost/boost-1_56_0;boost/boost_1_56_0;boost-1_56;boost_1_56;boost/boost-1_56;boost/boost_1_56;boost-1_55_0;boost_1_55_0;boost/boost-1_55_0;boost/boost_1_55_0;boost-1_55;boost_1_55;boost/boost-1_55;boost/boost_1_55;boost-1_54_0;boost_1_54_0;boost/boost-1_54_0;boost/boost_1_54_0;boost-1_54;boost_1_54;boost/boost-1_54;boost/boost_1_54 [ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:639 ] location of version.hpp: D:/boost_1_54_0/boost/version.hpp [ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:663 ] version.hpp reveals boost 1.54.0 [ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:739 ] guessed _boost_COMPILER = -vc120 [ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:749 ] _boost_MULTITHREADED = -mt [ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:792 ] _boost_RELEASE_ABI_TAG = - [ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:794 ] _boost_DEBUG_ABI_TAG = -gd [ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:842 ] _boost_LIBRARY_SEARCH_DIRS = D:/boost_1_54_0/lib;D:/boost_1_54_0/stage/lib;D:/boost_1_54_0/lib;D:/boost_1_54_0/../lib;D:/boost_1_54_0/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib [ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:930 ] Searching for THREAD_LIBRARY_RELEASE: libboost_thread-vc120-mt-1_54;libboost_thread-vc120-mt;libboost_thread-mt-1_54;libboost_thread-mt;libboost_thread;libboost_thread-vc120-mt-s-1_54;libboost_thread-vc120-mt-s;libboost_thread-mt-s-1_54;libboost_thread-mt-s [ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:966 ] Searching for THREAD_LIBRARY_DEBUG: libboost_thread-vc120-mt-gd-1_54;libboost_thread-vc120-mt-gd;libboost_thread-mt-gd-1_54;libboost_thread-mt-gd;libboost_thread-mt;libboost_thread;libboost_thread-vc120-mt-s-gd-1_54;libboost_thread-vc120-mt-s-gd;libboost_thread-mt-s-gd-1_54;libboost_thread-mt-s-gd [ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:930 ] Searching for SYSTEM_LIBRARY_RELEASE: libboost_system-vc120-mt-1_54;libboost_system-vc120-mt;libboost_system-mt-1_54;libboost_system-mt;libboost_system;libboost_system-vc120-mt-s-1_54;libboost_system-vc120-mt-s;libboost_system-mt-s-1_54;libboost_system-mt-s [ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:966 ] Searching for SYSTEM_LIBRARY_DEBUG: libboost_system-vc120-mt-gd-1_54;libboost_system-vc120-mt-gd;libboost_system-mt-gd-1_54;libboost_system-mt-gd;libboost_system-mt;libboost_system;libboost_system-vc120-mt-s-gd-1_54;libboost_system-vc120-mt-s-gd;libboost_system-mt-s-gd-1_54;libboost_system-mt-s-gd [ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:930 ] Searching for LOG_LIBRARY_RELEASE: libboost_log-vc120-mt-1_54;libboost_log-vc120-mt;libboost_log-mt-1_54;libboost_log-mt;libboost_log;libboost_log-vc120-mt-s-1_54;libboost_log-vc120-mt-s;libboost_log-mt-s-1_54;libboost_log-mt-s [ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:966 ] Searching for LOG_LIBRARY_DEBUG: libboost_log-vc120-mt-gd-1_54;libboost_log-vc120-mt-gd;libboost_log-mt-gd-1_54;libboost_log-mt-gd;libboost_log-mt;libboost_log;libboost_log-vc120-mt-s-gd-1_54;libboost_log-vc120-mt-s-gd;libboost_log-mt-s-gd-1_54;libboost_log-mt-s-gd [ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:930 ] Searching for LOG_SETUP_LIBRARY_RELEASE: libboost_log_setup-vc120-mt-1_54;libboost_log_setup-vc120-mt;libboost_log_setup-mt-1_54;libboost_log_setup-mt;libboost_log_setup;libboost_log_setup-vc120-mt-s-1_54;libboost_log_setup-vc120-mt-s;libboost_log_setup-mt-s-1_54;libboost_log_setup-mt-s [ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:966 ] Searching for LOG_SETUP_LIBRARY_DEBUG: libboost_log_setup-vc120-mt-gd-1_54;libboost_log_setup-vc120-mt-gd;libboost_log_setup-mt-gd-1_54;libboost_log_setup-mt-gd;libboost_log_setup-mt;libboost_log_setup;libboost_log_setup-vc120-mt-s-gd-1_54;libboost_log_setup-vc120-mt-s-gd;libboost_log_setup-mt-s-gd-1_54;libboost_log_setup-mt-s-gd [ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:930 ] Searching for PROGRAM_OPTIONS_LIBRARY_RELEASE: libboost_program_options-vc120-mt-1_54;libboost_program_options-vc120-mt;libboost_program_options-mt-1_54;libboost_program_options-mt;libboost_program_options;libboost_program_options-vc120-mt-s-1_54;libboost_program_options-vc120-mt-s;libboost_program_options-mt-s-1_54;libboost_program_options-mt-s [ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:966 ] Searching for PROGRAM_OPTIONS_LIBRARY_DEBUG: libboost_program_options-vc120-mt-gd-1_54;libboost_program_options-vc120-mt-gd;libboost_program_options-mt-gd-1_54;libboost_program_options-mt-gd;libboost_program_options-mt;libboost_program_options;libboost_program_options-vc120-mt-s-gd-1_54;libboost_program_options-vc120-mt-s-gd;libboost_program_options-mt-s-gd-1_54;libboost_program_options-mt-s-gd [ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:1017 ] Boost_FOUND = 1 CMake Error at C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:1106 (message): Unable to find the requested Boost libraries. Boost version: 1.54.0 Boost include path: D:/boost_1_54_0 The following Boost libraries could not be found: boost_thread boost_system boost_log boost_log_setup boost_program_options No Boost libraries were found. You may need to set BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT to the location of Boost. Call Stack (most recent call first): CMakeLists.txt:26 (find_package)
I have also tried writing set(Boost_USE_STATIC_LIBS ON), but unfortunately it did not help. Suggestions are most welcome. Thanks.
-
ComicSansMS over 10 yearsSince the Op builds under VS, his library files probably ended up under
stage
instead oflib
. That being said, setting anything apart fromBOOST_ROOT
yourself inside CMake is already more or less asking for trouble. -
Alexander Shukaev over 10 years@ComicSansMS: Of course it is. But I'm giving him a suggestion how to test whether his setup is supposed to work at all. Setting paths explicitly inside
CMakeLists.txt
is indeed against general recommendations and I'll drop a note about it and edit my answer with better option as soon as the author confirms that at least this works for him. Even settingBOOST_ROOT
is bad practice by the way. All these path-hint variables should be set during the invocation of CMake because they depend exclusively on the current environment. -
user1382494 over 10 years@Haroogan: Thank you very much for the detailed reply. Currently I had to format my machine and am facing some troubles regarding few tasks. I will get back to this as soon as I fix that thing. Thanks once again for your patience.
-
user1382494 over 10 years@Haroogan: I cleaned up my CmakeLists.txt file and performed the steps as suggested by you. But, still the same error persists. I, then uninstalled MS Visual Studio 2013 and installed MS Visual Studio 2012 and tried once again. Still the error persists. Then, I installed Boost 1.54.0 and Cmake in Ubuntu and it's working perfectly fine in Ubuntu. Hence, I am working on it in Ubuntu now to save time.
-
Alexander Shukaev over 10 yearsHave you tried both
set(BOOST_LIBRARYDIR D:/boost_1_54_0/lib)
andset(BOOST_LIBRARYDIR D:/boost_1_54_0/lib/stage)
? Furthermore, I see that you are using VS 2013, and debugging shows that CMake is not searching for*-vc130-*
libraries, it only searches for*-vc120-*
. This could very much be the reason. Do you have Boost libraries for VS 12 or VS 13? -
user1382494 over 10 yearsYes I had tried both the paths. Yes, the VS 13 was giving many problems, so I tried with VS 12 too, but nothing changed. Nevertheless, in Ubuntu, everything is working fine now.
-
Nathan Smiechowski almost 5 yearsIn my case, two problems were preventing the build. The directory structure was pretty weird and I hadn't specified set(Boost_USE_STATIC_LIBS ON) in cmakelists.txt.