Cannot specify BOOST_ROOT for cmake - boost

I have multiple versions of Boost installed (Windows 7/MinGW). I need to use a particular one (1.53.0).
I defined BOOST_ROOT in the CMakeFiles.txt file: SET(BOOST_ROOT C:/boost_1_53_0/), but I keep getting this error:
> cmake .
BOOST_ROOT=C:/boost_1_53_0/
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:1191 (message):
Unable to find the requested Boost libraries.
Boost version: 1.48.0
Boost include path: C:/Boost/include/boost-1_48
Detected version of Boost is too old. Requested version was 1.53 (or
newer).
The following Boost libraries could not be found:
boost_filesystem
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.
I also defined BOOST_ROOT as an environment variable, but with the same result.
Why is cmake still looking for the old version?

Try this:
cmake -DBOOST_ROOT=path

I also struggled with this same problem for a while. If this is the same issue that I had, then the problem is you aren't running the CMake configuration completely fresh without any cache. Once it runs once and finds the default installation (C:\Boost or /usr/include) it will continue to find that one regardless of the value of BOOST_ROOT. So make sure to completely delete any generated build files. Then set BOOST_ROOT to your desired separate installation and it should work fine.
This is also mentioned by jaor on the previously linked question: How can I get cmake to find my alternative boost installation?

If you are using a precompiled version of Boost libraries for Visual Studio, they come in a specific flavor of MSVC version and bitness. I needed to point CMake to that specific location - in my case, setting BOOST_ROOT to C:/local/boost_1_59_0 and BOOST_LIBRARYDIR to C:/local/boost_1_59_0/lib64-msvc-11.0 helped.

Related

How to properly link boost with cmake

The root directory of boost ($ENV{BOOST_ROOT}) is
C:\Boost\boost_1_64_0
All compiled libraries (.dll, .lib) are in
C:\Boost\boost_1_64_0\lib64-msvc-14.1
They have both boost_xxx and libboost_xxx.
My cmake file is
set(BOOST_ROOT "$ENV{BOOST_ROOT}")
set(BOOST_LIBRARYDIR "$ENV{BOOST_ROOT}/lib64-msvc-14.1")
message("${BOOST_ROOT}")
message("${BOOST_LIBRARYDIR}")
message("${Boost_INCLUDE_DIR}")
if(MSVC)
add_definitions(-DBOOST_ALL_NO_LIB)
add_definitions(-DBOOST_ALL_DYN_LINK)
endif()
find_package(Boost 1.64.0 COMPONENTS system filesystem program_options REQUIRED)
And the output is
C:\Boost\boost_1_64_0
C:\Boost\boost_1_64_0/lib64-msvc-14.1
C:/Boost/boost_1_64_0
CMake Error at C:/Program
Files/CMake/share/cmake-3.8/Modules/FindBoost.cmake:1842 (message):
Unable to find the requested Boost libraries.
Boost version: 1.64.0
Boost include path: C:/Boost/boost_1_64_0
Could not find the following Boost libraries:
boost_system
boost_filesystem
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:78 (find_package)
CMake Error at CMakeLists.txt:84 (message): Boost not found
Could someone help please? I have spent hours on this but couldn't figure out why this doesn't work.
First of all, what CMake version do you use? Recently a regression fix was included into 3.8.1 release -- it was about backslashes in BOOST_ROOT.
Secondly, you don't need to specify anything else ('cept maybe the BOOST_ROOT) if you are using official prebuilt Windows binaries -- FindBoost.cmake would try to find them as well. (Unfortunately I can't recall since what version.)
Never do set(BOOST_ROOT...) in your CMakeLists.txt -- just pass this parameter to cmake run via -D option. A better way is the following:
if(NOT DEFINED BOOST_ROOT AND NOT "${ENV{BOOST_ROOT}" STREQUAL "")
set(BOOST_ROOT "$ENV{BOOST_ROOT}")
endif()
Use imported targets to link w/ needed Boost libraries and to modify compile/linker flags per taget. Please avoid to modify "global" compiler/linker options -- i.e. use corresponding target_xxx commands instead of add_definitions & etc.
I use the following script to load boost with CMake (working with Linux and Windows) :
set(BoostPath "${DefaultBoostPath}" CACHE PATH "Path to Boost")
message(STATUS "Path to Boost: ${BoostPath}")
set(BOOST_ROOT "${BoostPath}")
set(Boost_USE_MULTITHREAD ON)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_NO_SYSTEM_PATHS ON)
set(Boost_ADDITIONAL_VERSIONS "1.57.0" "1.57" "1.58.0" "1.58" "1.59.0" "1.59" "1.60.0" "1.60" "1.61.0" "1.61" "1.62.0" "1.62" "1.63.0" "1.63" "1.64.0" "1.64")
find_package(Boost ${RequiredBoostVersion} REQUIRED COMPONENTS ${RequiredBoostComponents})
mark_as_advanced(FORCE Boost_DIR)
set(BoostVersion "${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}")
message(STATUS "Boost version: ${BoostVersion}")
if(CompilerName STREQUAL "gcc")
set(System_LIBRARIES ${System_LIBRARIES} pthread rt)
endif()
You can see I have to add some versions of Boost because my version of CMake doesn't know last versions.
What's your CMake version ? Maybe it's the same problem.
Where are your headers? I don't think it found the include directory (which is necessary for this to be successful).
Search for FindBoost.cmake in your cmake installation directory, there are lots of useful things in there for troubleshooting.
using set(Boost_DEBUG ON) can help you figure out which paths are searched and what the filenames of the libraries are searched. You can specify the include directory (directory where folder boost is stored) with set(Boost_INCLUDEDIRS ${BOOST_ROOT}/inc), though what I just showed is one of the places that FindBoost.cmake searches.
Also, you don't need set(BOOST_ROOT "$ENV{BOOST_ROOT}"). FindBoost.cmake does that for you if you don't set ${BOOST_ROOT}.
Note that if you just downloaded boost, extracted the archive to ${BOOST_ROOT} and compiled with b2, then all of your files are in ${BOOST_ROOT}/stage. This is also a good place for them to reside. If you manually copy files somewhere else, then FindBoost may have some troubles finding them.

could not find the following boost libraries

I am not able to figure out why am I getting this error.
CMake Error at C:/Program Files/CMake/share/cmake-3.6/Modules/FindBoost.cmake:1753 (message):
Unable to find the requested Boost libraries.
Boost version: 1.48.0
Boost include path: D:/Shark/boost_1_48_0
Could not find the following Boost libraries:
boost_system
boost_date_time
boost_filesystem
boost_program_options
boost_serialization
boost_thread
boost_unit_test_framework
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:146 (find_package)
CMake Error at CMakeLists.txt:154 (message):
Please make sure Boost 1.48.0 is installed on your system
It says, Unable to find requested boost library. But I have installed boost 1.48.0 and build it using Visual studio console, and have passed BOOST_LIBRARYDIR=D:/Shark/boost_1_48_0/stage/lib and BOOST_ROOT=D:/Shark/boost_1_48_0.
CMake's FindBoost macros look for the libs in various spots based on the compiler your using. Even if you specify BOOST_LIBRARYDIR, you still have to conform to the standards the FindBoost macro expects for filenames ie:
${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG}-${Boost_LIB_VERSION}
${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG}
${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG}-${Boost_LIB_VERSION}
${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG}
${Boost_LIB_PREFIX}boost_${COMPONENT} )
Example filenames matching this template for visual studio 2013 (aka msvc 12)
$BOOST_LIBRARY_DIR/boost_atomic-vc120-mt-1_58.dll
$BOOST_LIBRARY_DIR/boost_atomic-vc120-mt-gd-1_58.dll
You'll note that the mt for multithreaded build and the gd to indicate it's a debug build. FindBoost is fussy and will look for the debug build if your CMake project has a CMAKE_BUILD_TYPE=Debug
Additionally if your building multithreaded you'll need to define:
Boost_USE_MULTITHREADED=ON
If your still having trouble you define: Boost_DEBUG=1 and you'll see a lot of additional output about how and where FindBoost is searching.
I was building the boost library by downloading source file. The problem was it was not creating .dll (only .lib).
I downloaded boost binary and installed it from installer to get those files, and set the path BOOL_LIBRARYDIR=C:/local/boost/lib64-msvc-14.0 and BOOL_ROOT=C:/local/boost to make it done.

Finding Qt with CMake: Missing moc, uic, rcc

I'm trying to fix the installation of a custom built Qt. I'm using the qt.conf from this very similar question. However, CMake 2.8.7 is still unable to find moc, uic, and rcc.
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:97 (MESSAGE):
Could NOT find Qt4 (missing: QT_MOC_EXECUTABLE QT_RCC_EXECUTABLE
QT_UIC_EXECUTABLE) (found suitable exact version "4.8.1")
I have manually set the QT_QMAKE_EXECUTABLE variable to the correct value, namely B:/lib/vs10/Qt-4.8.1-VS10x64/bin/qmake.exe. After deploying the qt.conf file, qmake -v returns the correct path:
c:\>B:/lib/vs10/Qt-4.8.1-VS10x64/bin/qmake.exe -v
QMake version 2.01a
Using Qt version 4.8.1 in B:/lib/vs10/Qt-4.8.1-VS10x64/lib
qmake -query QT_INSTALL_PREFIX also returns the correct path. Note that I can't use environment variables because we need different Qt versions for different projects.
What am I missing?
You should set CMAKE_PREFIX_PATH to B:/lib/vs10/Qt-4.8.1-VS10x64/bin instead of setting QT_QMAKE_EXECUTABLE. It will help cmake to find all qt executables.
The problem was that they decided to make QT_BINARY_DIR a CACHE INTERNAL variable, which wasn't reset properly after changing qt.conf and deleting the QT_* variables in CMake. QT_BINARY_DIR is only reset if the path of the qmake.exe changes. After clearing the cache it worked.
The lessons I draw from this: Don't use CACHE INTERNAL, just FORCE and mark_as_advanced.

cmake is using the wrong cboost libs

i try to compile a program with cmake, but I got stock with this error:
Unable to find the requested Boost libraries.
Boost version: 1.34.1
Boost include path: /usr/include
Detected version of Boost is too old. Requested version was 1.37 (or
newer).
The following Boost libraries could not be found:
boost_program_options
boost_filesystem
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.
I installed already the new boost package under /home/dev/boost_1_45_0.
But always when I try to run cmake again I get still the same error.
I also set
export BOOST_ROOT=/home/dev/boost_1_45_0
But when I execute cd ${BOOST_ROOT} I'm in the right folder.
Can anybody help me? Thanks!
Try to delete your build tree, and then run:
cmake -DBOOST_ROOT=/home/dev/boost_1_45_0 path/to/src path/to/build

Cmake doesn't find Boost

I'm trying to configure a project using CMake, but it fails to find Boost libraries even though they are in the specified folder. I have specified Boost_INCLUDE_DIR, Boost_LIBRARYDIR and BOOST_ROOT , but I still get an error saying that CMake is not able to find Boost. What could be the reason of such error?
Are you sure you are doing it the correct way? The idea is that CMake sets BOOST_INCLUDE_DIR, BOOST_LIBRARYDIR and BOOST_ROOT automatically. Do something like this in CMakeLists.txt:
FIND_PACKAGE(Boost)
IF (Boost_FOUND)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
ADD_DEFINITIONS( "-DHAS_BOOST" )
ENDIF()
If boost is not installed in a default location and can, thus, not be found by CMake, you can tell CMake where to look for boost like this:
SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "C:/win32libs/boost")
SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "C:/win32libs/boost/lib")
Of course, those two lines have to be before the FIND_PACKAGE(Boost) in CMakeLists.txt.
There is more help available by reading the FindBoost.cmake file itself. It is located in your 'Modules' directory.
A good start is to set(Boost_DEBUG 1) - this will spit out a good deal of information about where boost is looking, what it's looking for, and may help explain why it can't find it.
It can also help you to figure out if it is picking up on your BOOST_ROOT properly.
FindBoost.cmake also sometimes has problems if the exact version of boost is not listed in the Available Versions variables. You can find more about this by reading FindBoost.cmake.
Lastly, FindBoost.cmake has had some bugs in the past. One thing you might try is to take a newer version of FindBoost.cmake out of the latest version of CMake, and stick it into your project folder alongside CMakeLists.txt - then even if you have an old version of boost, it will use the new version of FindBoost.cmake that is in your project's folder.
Good luck.
For me this error was simply because boost wasn't installed so on ubuntu:
sudo apt install build-essential libboost-system-dev libboost-thread-dev libboost-program-options-dev libboost-test-dev
I struggled with this problem for a while myself. It turned out that cmake was looking for Boost library files using Boost's naming convention, in which the library name is a function of the compiler version used to build it. Our Boost libraries were built using GCC 4.9.1, and that compiler version was in fact present on our system; however, GCC 4.4.7 also happened to be installed. As it happens, cmake's FindBoost.cmake script was auto-detecting the GCC 4.4.7 installation instead of the GCC 4.9.1 one, and thus was looking for Boost library files with "gcc44" in the file names, rather than "gcc49".
The simple fix was to force cmake to assume that GCC 4.9 was present, by setting Boost_COMPILER to "-gcc49" in CMakeLists.txt. With this change, FindBoost.cmake looked for, and found, my Boost library files.
You can also specify the version of Boost that you would like CMake to use by passing -DBOOST_INCLUDEDIR or -DBOOST_ROOT pointing to the location of correct version boost headers
Example:
cmake -DBOOST_ROOT=/opt/latestboost
This will also be useful when multiple boost versions are on the same system.
I also had a similar problem and discovered that the BOOST_INCLUDE_DIR, BOOST_LIBRARYDIR and BOOST_ROOT env variables must hold absolute paths.
HTH!
In my case Boost was not installed. I used below command on Mac and then cmake find_package(Boost) works like a charm
brew install Boost
Please note upper case 'B' in Boost!
If you are building your own boost do not forget to use the --layout=versioned otherwise the search for a particular version of library will fail
For cmake version 3.1.0-rc2 to pick up boost 1.57 specify -D_boost_TEST_VERSIONS=1.57
cmake version 3.1.0-rc2 defaults to boost<=1.56.0 as is seen using -DBoost_DEBUG=ON
cmake -D_boost_TEST_VERSIONS=1.57 -DBoost_DEBUG=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
One more bit of advice for anyone trying to build CGAL in particular, with statically linked Boost. It is not enough to define Boost_USE_STATIC_LIBS; it gets overridden by the time Boost_DEBUG outputs its value. The thing to do here is to check the "Advanced" checkbox and to enable CGAL_Boost_USE_STATIC_LIBS.
I had the same problem while trying to run make for a project after installing Boost version 1.66.0 on Ubuntu Trusty64. The error message was similar to (not exactly like) this one:
CMake Error at
/usr/local/Cellar/cmake/3.3.2/share/cmake/Modules/FindBoost.cmake:1245 (message):
Unable to find the requested Boost libraries.
Boost version: 0.0.0
Boost include path: /usr/include
Detected version of Boost is too old. Requested version was 1.36 (or newer).
Call Stack (most recent call first):
CMakeLists.txt:10 (FIND_PACKAGE)
Boost was definitely installed, but CMake couldn't detect it. After spending plenty of time tinkering with paths and environmental variables, I eventually ended up checking cmake itself for options and found the following:
--check-system-vars = Find problems with variable usage in system files
So I ran the following in the directory at issue:
sudo cmake --check-system-vars
which returned:
Also check system files when warning about unused and uninitialized variables.
-- Boost version: 1.66.0
-- Found the following Boost libraries:
-- system
-- filesystem
-- thread
-- date_time
-- chrono
-- regex
-- serialization
-- program_options
-- Found Git: /usr/bin/git
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/myproject
and resolved the issue.
See FindBoost.cmake first. The variables you set are the correct ones but they should be all uppercase.
Make sure the library architecture matches with CMake configuration.
cmake -A x64 ..
I suggest creating a minimal executable which only includes a Boost library to see if it compiles.
#include <iostream>
#include <boost/date_time.hpp>
int main() {
using namespace std;
using namespace boost::gregorian;
date today = day_clock::local_day();
cout << today << endl;
}
find_package(Boost REQUIRED COMPONENTS
date_time
)
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIRS})
add_executable(test_boost "test_boost.cpp")
target_link_libraries(test_boost Boost::date_time)
Start debugging by checking Boost_FOUND first.
message(STATUS "Boost_FOUND: ${Boost_FOUND}")
The version should be found even if no libraries are found. (Boost_VERSION)
If Boost_LIBRARY_DIRS becomes non-empty, it should compile.
I had the same problem, and none of the above solutions worked. Actually, the file include/boost/version.hpp could not be read (by the cmake script launched by jenkins).
I had to manually change the permission of the (boost) library (even though jenkins belongs to the group, but that is another problem linked to jenkins that I could not figure out):
chmod o+wx ${BOOST_ROOT} -R # allow reading/execution on the whole library
#chmod g+wx ${BOOST_ROOT} -R # this did not suffice, strangely, but it is another story I guess
This can also happen if CMAKE_FIND_ROOT_PATH is set as different from BOOST_ROOT.
I faced the same issue that in spite of setting BOOST_ROOT, I was getting the error.
But for cross compiling for ARM I was using Toolchain-android.cmake in which I had (for some reason):
set(BOOST_ROOT "/home/.../boost")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --sysroot=${SYSROOT}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --sysroot=${SYSROOT} -I${SYSROOT}/include/libcxx")
set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS}")
set(CMAKE_FIND_ROOT_PATH "${SYSROOT}")
CMAKE_FIND_ROOT_PATH seems to be overriding BOOST_ROOT which was causing the issue.
For those using python3.7 docker image, this solved:
apt install libboost-system-dev libboost-thread-dev
Maybe
brew install boost
will help you.

Resources