I have compiled Boost 1.51.0 on Windows using the rubenvb's CLang build. I actually compiled b2 using MinGW:
bootstrap mingw
... compiling b2 using mingw...
and then I compiled the libraries with CLang:
b2 toolset=clang stage --stagedir=. --build-type=complete --with-regex ...
By the way, even if I specified --build-type=complete there are no DLLs in lib directory, but I read somewhere that CLang has still problem with linking on Windows so that might be the reason. Anyway static libraries are fine for me. I got these files in %BOOST_ROOT%\lib:
libboost_regex-clang31-1_51.lib
libboost_regex-clang31-d-1_51.lib
libboost_regex-clang31-mt-1_51.lib
libboost_regex-clang31-mt-d-1_51.lib
libboost_regex-clang31-mt-s-1_51.lib
libboost_regex-clang31-mt-sd-1_51.lib
libboost_regex-clang31-s-1_51.lib
libboost_regex-clang31-sd-1_51.lib
Now, if I compile something with CLang from command line everything works. The problem shows when I try to make CMake find Boost libraries: it simply could not find them. I tried with this CMakeFiles.txt:
cmake_minimum_required (VERSION 2.8)
project(ccc)
# Setting/unsetting this does not change anything.
set(Boost_USE_STATIC_LIBS ON)
find_package(Boost COMPONENTS regex REQUIRED)
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIRS})
add_executable(ccc main.cpp)
target_link_libraries(ccc
${Boost_REGEX_LIBRARY}
)
Building it using MinGW (and a MinGW compiled version of Boost) it works. If I try with CLang (after having setted CC=clang, CXX=clang++ and BOOST_ROOT=C:/misc/boost/clang-1_51_0) it does not:
D:\Desktop\ppp>cmake -G "MinGW Makefiles" ..\ccc
-- The C compiler identification is Clang 3.1.0
-- The CXX compiler identification is Clang 3.1.0
-- Check for working C compiler: C:/misc/clang/bin/clang.exe
-- Check for working C compiler: C:/misc/clang/bin/clang.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/misc/clang/bin/clang++.exe
-- Check for working CXX compiler: C:/misc/clang/bin/clang++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMake Error at C:/misc/cmake/share/cmake-2.8/Modules/FindBoost.cmake:1191 (message):
Unable to find the requested Boost libraries.
Boost version: 1.51.0
Boost include path: C:/misc/boost/clang-1_51_0
The following Boost libraries could not be found:
boost_regex
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:5 (find_package)
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
Boost_REGEX_LIBRARY (ADVANCED)
linked by target "ccc" in directory D:/Desktop/ccc
-- Configuring incomplete, errors occurred!
However, if I compile manually it works again:
clang++ main.cpp -I%BOOST_ROOT% -L%BOOST_ROOT%\lib -llibboost_regex-clang31-1_51
...Ok, and the executable works
Manually setting BOOST_LIBRARYDIR does not work either. Neither does using backslashes \.
Looking inside the file "C:/misc/cmake/share/cmake-2.8/Modules/FindBoost.cmake" you can find a list of all the variables related to Boost you can use. The one you need is Boost_COMPILER (Boost_DETAILED_FAILURE_MSG can also be useful to diagnose problems):
# Boost_COMPILER Set this to the compiler suffix used by Boost
# (e.g. "-gcc43") if FindBoost has problems finding
# the proper Boost installation
Related
I'm trying to compile a simple C++ program which uses CGAL to WASM. The problem is that for some reason find_package(CGAL) fails when using emsmake cmake, though it works fine when using cmake for compiling regular executables. I'm pretty new to compiling C++ and working with Emscripten, so this is most likely a noob question.
Running emcmake (notice CGAL warning):
cgal % emcmake cmake .
configure: cmake . -DCMAKE_TOOLCHAIN_FILE=/Users/kitty/Downloads/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_CROSSCOMPILING_EMULATOR=/Users/kitty/Downloads/emsdk/node/14.18.2_64bit/bin/node;--experimental-wasm-threads
-- This project requires the CGAL library, and will not be compiled.
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/kitty/Projects/cgal
Running regular cmake (no warning):
cgal % cmake .
-- The C compiler identification is AppleClang 13.1.6.13160021
-- The CXX compiler identification is AppleClang 13.1.6.13160021
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Warning at /usr/local/lib/cmake/CGAL/CGALConfig.cmake:92 (message):
CGAL_DATA_DIR cannot be deduced, set the variable CGAL_DATA_DIR to set the
default value of CGAL::data_file_path()
Call Stack (most recent call first):
CMakeLists.txt:10 (find_package)
-- Using header-only CGAL
-- Targetting Unix Makefiles
-- Using /Library/Developer/CommandLineTools/usr/bin/c++ compiler.
-- DARWIN_VERSION=21
-- Mac Leopard detected
-- Found GMP: /usr/local/lib/libgmp.dylib
-- Found MPFR: /usr/local/lib/libmpfr.dylib
-- Found Boost: /usr/local/lib/cmake/Boost-1.78.0/BoostConfig.cmake (found suitable version "1.78.0", minimum required is "1.48")
-- Boost include dirs: /usr/local/include
-- Boost libraries:
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Found Boost: /usr/local/lib/cmake/Boost-1.78.0/BoostConfig.cmake (found version "1.78.0")
CMake Warning at /usr/local/lib/cmake/CGAL/CGAL_enable_end_of_configuration_hook.cmake:99 (message):
=======================================================================
CGAL performance notice:
The variable CMAKE_BUILD_TYPE is set to "". For performance reasons, you
should set CMAKE_BUILD_TYPE to "Release".
Set CGAL_DO_NOT_WARN_ABOUT_CMAKE_BUILD_TYPE to TRUE if you want to disable
this warning.
=======================================================================
Call Stack (most recent call first):
CMakeLists.txt:9223372036854775807 (CGAL_run_at_the_end_of_configuration)
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/kitty/Projects/cgal
Running make afterwards produces a working executable.
CMakeLists.txt (for the most part generated using cgal_create_CMakeLists utility):
# Created by the script cgal_create_CMakeLists
# This is the CMake script for compiling a set of CGAL applications.
cmake_minimum_required(VERSION 3.1...3.15)
project( executable )
# CGAL and its components
find_package( CGAL QUIET COMPONENTS )
if ( NOT CGAL_FOUND )
message(STATUS "This project requires the CGAL library, and will not be compiled.")
return()
endif()
# Boost and its components
find_package( Boost REQUIRED )
if ( NOT Boost_FOUND )
message(STATUS "This project requires the Boost library, and will not be compiled.")
return()
endif()
# include for local directory
# include for local package
# Creating entries for target: executable
# ############################
add_executable( executable test.cpp )
add_to_cached_list( CGAL_EXECUTABLE_TARGETS executable )
# Link the executable to CGAL and third-party libraries
target_link_libraries(executable PRIVATE CGAL::CGAL )
# Lines below are commented for now as they are not required for minimal repro
#set(CMAKE_EXECUTABLE_SUFFIX ".wasm")
#set_target_properties(executable PROPERTIES LINK_FLAGS "-s WASM=1 -s EXPORTED_FUNCTIONS='[_main]'")
test.cpp:
#include <iostream>
int main() {
std::cout << "Hello World!";
return 0;
}
In order for emcmake cmake .. to find the CGAL you would need to build that project for wasm and install it into the emscripten sysroot. (normally emscripten/cache/sysroot). Any libraries in /usr/lib or /usr/local/lib are most likely host libraries and therefore not compatible with wasm or emscripten.
I've searched high and low for this answer and I think it should be answered in a modern setting. Most things I see are from 2013 or at the latest 2015 with comments from 2019.
to start off I am using macOS 11.2 with the most recent version of xcode 12.4.
I cloned and installed from git the most recent (as of today) repositories for boost and emscripten.
for some reason on my project when trying to integrate enscripten flags into my CMakeLists.txt file I get an error running
$ cmake .. then $ make.
the CMakeLists.txt file:
cmake_minimum_required(VERSION 3.17)
project(FernQuest) #emscripten version
if (${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
message(STATUS "using emscripten")
endif ()
if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
message(STATUS "using cmake")
endif ()
#options
option(JS_ONLY "Compiles to native JS (No WASM)" OFF)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/out)
include_directories(.)
include_directories(/usr/local/include) #where boost in located
message(STATUS "finding boost!")
find_package(Boost 1.74.0 REQUIRED serialization system filesystem COMPONENTS serialization system filesystem)
if(Boost_FOUND)
message(STATUS "found boost!")
endif()
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIR})
if(NOT Boost_FOUND)
message(FATAL_ERROR "Could not find boost!")
endif()
message(STATUS "setting sources")
SET(FQ_SRCS
../src/FernQuest.cpp
../src/Item.cpp
../src/Item.h
../src/Player.cpp
../src/Player.h
../src/Game.cpp
../src/Game.h
../src/QuestLog.cpp
../src/QuestLog.h)
SET(CMAKE_C_COMPILER emcc)
SET(CMAKE_CPP_COMPILER em++)
add_executable(FernQuest ${FQ_SRCS})
if(Boost_FOUND)
if(JS_ONLY)
message(STATUS "Setting compilation target to native JavaScript")
set(CMAKE_EXECUTABLE_SUFFIX ".js")
set_target_properties(FernQuest PROPERTIES COMPILE_FLAGS "-s USE_BOOST_HEADERS=1" LINK_FLAGS "-s USE_BOOST_HEADERS=1 -s WASM=0 -s EXPORTED_FUNCTIONS='[_main]'")
else(JS_ONLY)
message(STATUS "Setting compilation target to WASM")
set(CMAKE_EXECUTABLE_SUFFIX ".wasm.js")
set_target_properties(FernQuest PROPERTIES COMPILE_FLAGS "-s USE_BOOST_HEADERS=1" LINK_FLAGS " -s USE_BOOST_HEADERS=1 -s WASM=1 -s EXPORTED_FUNCTIONS='[_main]'")
endif(JS_ONLY)
endif()
the error:
-- The C compiler identification is AppleClang 12.0.0.12000032
-- The CXX compiler identification is AppleClang 12.0.0.12000032
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- using cmake
-- finding boost!
-- Found Boost: /usr/local/lib/cmake/Boost-1.76.0/BoostConfig.cmake (found suitable version "1.76.0", minimum required is "1.74.0") found components: serialization system filesystem serialization system filesystem
-- found boost!
-- setting sources
-- Setting compilation target to WASM
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/codiecottrell/Documents/FernQuest/emscripten/build
Scanning dependencies of target FernQuest
[ 16%] Building CXX object CMakeFiles/FernQuest.dir/Users/codiecottrell/Documents/FernQuest/src/FernQuest.cpp.o
clang: error: no such file or directory: 'USE_BOOST_HEADERS=1'
make[2]: *** [CMakeFiles/FernQuest.dir/Users/codiecottrell/Documents/FernQuest/src/FernQuest.cpp.o] Error 1
make[1]: *** [CMakeFiles/FernQuest.dir/all] Error 2
make: *** [all] Error 2
so I read up and they say that to fix this you use this below as to actually run it using the -DCMAKE_TOOLCHAIN_FILE:
$ emcmake cmake .. then $ emmake make
this error occurs:
configure: cmake .. -DCMAKE_TOOLCHAIN_FILE=/Users/codiecottrell/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_CROSSCOMPILING_EMULATOR="/Users/codiecottrell/emsdk/node/14.15.5_64bit/bin/node"
-- using emscripten
-- finding boost!
CMake Error at /usr/local/Cellar/cmake/3.19.4/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:218 (message):
Could NOT find Boost (missing: Boost_INCLUDE_DIR serialization system
filesystem serialization system filesystem) (Required is at least version
"1.74.0")
Call Stack (most recent call first):
/usr/local/Cellar/cmake/3.19.4/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:582 (_FPHSA_FAILURE_MESSAGE)
/usr/local/Cellar/cmake/3.19.4/share/cmake/Modules/FindBoost.cmake:2193 (find_package_handle_standard_args)
CMakeLists.txt:21 (find_package)
-- Configuring incomplete, errors occurred!
See also "/Users/codiecottrell/Documents/FernQuest/emscripten/build/CMakeFiles/CMakeOutput.log".
make: make
-- using emscripten
-- finding boost!
CMake Error at /usr/local/Cellar/cmake/3.19.4/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:218 (message):
Could NOT find Boost (missing: Boost_INCLUDE_DIR serialization system
filesystem serialization system filesystem) (Required is at least version
"1.74.0")
Call Stack (most recent call first):
/usr/local/Cellar/cmake/3.19.4/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:582 (_FPHSA_FAILURE_MESSAGE)
/usr/local/Cellar/cmake/3.19.4/share/cmake/Modules/FindBoost.cmake:2193 (find_package_handle_standard_args)
CMakeLists.txt:21 (find_package)
-- Configuring incomplete, errors occurred!
See also "/Users/codiecottrell/Documents/FernQuest/emscripten/build/CMakeFiles/CMakeOutput.log".
make: *** [cmake_check_build_system] Error 1
My Question:
it seems that enscripten cannot find boost when running it through its own means, however cmake can clearly find it. There is also support for running boost through emscripten as I've read in both documentations however there is no clear way. What is this way and where am I going wrong? I'm going to continue to troubleshoot
EDIT
just tried $ emconfigure ./b2 toolset=gcc --prefix=/usr/local/B2
and it didn't change anything
If you're building with emscripten then the libraries on your mac (where cmake is searching) won't work; you will need to compile them statically.
I recommend trying to build your project without CMake.
If you're project only uses the boost headers (not libraries), then something like this might work:
$ em++ ../src/*.cpp -o index.html -s USE_BOOST_HEADERS=1
Otherwise you'll need to compile Boost also. Once you've done that and you have a libboost.a file, you'd compile your program like this:
$ em++ ../src/*.cpp -c -s USE_BOOST_HEADERS=1
Then link it:
$ em++ *.o /path/to/libboost.a -o index.html
Of course, depending on what other libraries you use you'll need to tweak those commands. But the general idea is to compile all the dependencies into static archive (.a) files, then compile those together to get the resulting .html (or .js or .wasm) file.
Read more about compiling with emcc.
I am following the instructions from https://badprog.com/c-boost-setting-up-on-windows-10 . I have Visual Studio 2017 installed, and installed boost_1_71_0-msvc-14.1-64.exe. CMake was downloaded from cmake.org/download/, cmake-3.19.0-rc1-win64-x64.msi.
I have a project that needs Boost Beast, which I believe is 1.70 or higher.
When I run cmake . everything seems fine:
C:\Users\Public\xyz>cmake .
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.18362.
-- The CXX compiler identification is MSVC 19.24.28314.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for C++ include pthread.h
-- Looking for C++ include pthread.h - not found
-- Found Threads: TRUE
-- Found Boost: C:/local/boost_1_71_0 (found suitable version "1.71.0", minimum required is "1.70") found components: thread system chrono date_time atomic
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/Public/xyz
The resulting project opens in Visual Studio 2017, but then complains it needs the 2019 build tools. Surprisingly, as you can see above, it's building for Visual Studio 2019?
But, after killing CMakeCache.txt and CMakeFiles, if I do this:
C:\Users\Public\xyz>cmake -G "Visual Studio 15 2017" .
-- Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.18362.
-- The CXX compiler identification is MSVC 19.16.27034.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for C++ include pthread.h
-- Looking for C++ include pthread.h - not found
-- Found Threads: TRUE
CMake Error at C:/Program Files/CMake/share/cmake-3.19/Modules/FindPackageHandleStandardArgs.cmake:218 (message):
Could NOT find Boost (missing: thread system) (found suitable version
"1.71.0", minimum required is "1.70")
Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-3.19/Modules/FindPackageHandleStandardArgs.cmake:577 (_FPHSA_FAILURE_MESSAGE)
C:/Program Files/CMake/share/cmake-3.19/Modules/FindBoost.cmake:2176 (find_package_handle_standard_args)
CMakeLists.txt:29 (FIND_PACKAGE)
-- Configuring incomplete, errors occurred!
See also "C:/Users/Public/xyz/CMakeFiles/CMakeOutput.log".
Suddenly it can't find Boost components (but can find Boost?). I've tried various forms of -DBOOST_LIBRARYDIR or -DBOOST_ROOT, etc., to no avail, but I don't seem to have the usual stackoverflow problem of cmake not being able to find Boost; instead it doesn't seem to recognize the Visual Studio 2017 target, despite having been installed for msvc-14.1?
CMakeLists.txt:
# Specify the minimum version for CMake
cmake_minimum_required(VERSION 3.1)
# Force C++11, for Boost Beast (async http library)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Project's name
project(xyz
VERSION 0.1
LANGUAGES CXX)
# Set the output folder where the program will be created
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/build)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
# Specify .cpp and .hpp is in src/
set(PROJECT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/src)
include_directories("${PROJECT_SOURCE_DIR}")
# Add source to build target for hello world...
add_executable(main ${PROJECT_SOURCE_DIR}/main.cpp)
# Testing http support
ADD_EXECUTABLE( server ${PROJECT_SOURCE_DIR}/server.cpp )
FIND_PACKAGE( Boost 1.70 REQUIRED COMPONENTS thread system )
INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIRS} )
target_link_libraries ( server LINK_PUBLIC ${Boost_LIBRARIES} )
In the end, the issue was simple. If I may so, it was an easy mistake for a beginner to make but almost impossible for a beginner to unravel with regular google searching.
When I issued cmake ., it was defaulting to a 64 bit build, but assuming a Visual Studio 2019 target. That was wrong.
The equivalent should have been cmake -G "Visual Studio 15 2017 Win64" . But not knowing this, and following the wrong tutorials, I was issuing instead cmake -G "Visual Studio 15 2017" .. This defaulted to a 32 bit build - though by default it never mentions this fact. It could find boost, but all library files were for 64 bit and useless for 32 bit, so it simply said "I can't find anything!".
My thanks to #Tsyvarev, who should get the credit for the answer. Turning on DEBUG and looking at searched library files character by character was indeed the right call.
Now that I've looked through other peoples solutions for several hours and could not find quite the right answer for my problem I would like to bring my specific problem to you. :)
I am trying to build vsomeip with CMake. For that I previously built boost 1.55, however, I get the following errors in CMake:
The C compiler identification is MSVC 19.0.24215.1
The CXX compiler identification is MSVC 19.0.24215.1
Check for working C compiler: C:/Program Files (x86)/Microsoft Visua Studio 14.0/VC/bin/cl.exe
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe -- works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Detecting C compile features
Detecting C compile features - done
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
Setting build type to 'RelWithDebInfo' as none was specified.
Looking for pthread.h
Looking for pthread.h - not found
Found Threads: TRUE
CMake Error at C:/Program Files/CMake/share/cmake-3.12/Modules/FindBoost.cmake:2025 (message):
Unable to find the requested Boost libraries.
Boost version: 1.55.0
Boost include path: C:/Program Files/boost/boost_1_55_0
Could not find the following static Boost libraries:
boost_system
boost_thread
boost_log
Some (but not all) of the required Boost libraries were found. You may
need to install these additional Boost libraries. Alternatively, 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:99 (find_package)
Boost was not found!
Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
Systemd was not found, watchdog disabled!
using MSVC Compiler
Predefined unicast address: 127.0.0.1
Predefined diagnosis address: 0x00
Predefined routing application: vsomeipd
Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
CMake Warning at CMakeLists.txt:335 (message):
Doxygen is not installed. Documentation can not be built.
CMake Warning at CMakeLists.txt:374 (message):
asciidoc is not installed. Readme can not be built.
GTEST_ROOT is not defined. For building the tests the variable
GTEST_ROOT has to be defined. Tests can not be built.
Configuring incomplete, errors occurred!
See also "D:/Desktop/BACHELORARBEIT/vsomeip/build/CMakeFiles /CMakeOutput.log".
See also "D:/Desktop/BACHELORARBEIT/vsomeip/build/CMakeFiles/CMakeError.log".
It cannot find the static Boost libraries. Now, I've tried playing around with the CMakeList.txt and here is the part of it that would be supposed to handle the linking:
# Boost
set(BOOST_INCLUDE_DIR C:/Program Files/Boost/boost_1_55_0)
set(BOOST_LIBRARYDIR C:/Program Files/Boost/boost_1_55_0/stage/libs)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
find_package( Boost 1.55 COMPONENTS system thread log REQUIRED )
include_directories( ${Boost_INCLUDE_DIR} )
if(Boost_FOUND)
if(Boost_LIBRARY_DIR)
MESSAGE( STATUS "Boost_LIBRARY_DIR not empty using it: ${Boost_LIBRARY_DIR}" )
else()
if(BOOST_LIBRARYDIR)
MESSAGE( STATUS "Boost_LIBRARY_DIR empty but BOOST_LIBRARYDIR is set setting Boost_LIBRARY_DIR to: ${BOOST_LIBRARYDIR}" )
set(Boost_LIBRARY_DIR ${BOOST_LIBRARYDIR})
endif()
endif()
else()
MESSAGE( STATUS "Boost was not found!")
endif()
I have also tried using a newer boost version (1.67) with same results. Any help will be dearly appreciated!
Check if your compiled libraries are in the following directory:
C:/Program Files/Boost/boost_1_55_0/stage/libs
If not, set your lib folder directory path:
set(BOOST_LIBRARYDIR path_to_lib_directory)
As #Tsyvarev suggested I used set(Boost_DEBUG ON) to trace the exact locations and files that CMake was looking for and the discovered several problems:
1.) Setting the path to "C:/Program Files/Boost/boost_1_55_0"
causes problems, because of the space in the path
2.) It searched for the libraries covering multiple formats like: boost_thread-vc141-mt-gd-x32-1_55.lib.
However, when I built boost with incorrect parameters, so my libs were built like this:
libboost_thread-vc-mt-1_55.lib, which is not of the correct format.
3.) Unfortunately adding other options when building boost, e.g.:
b2 toolset=msvc-14.1 address-model=32 --build-type=complete
caused other errors. Also building boost_1_67_0 manually worked for me at all.
My solution to the problem was to simply take one of the third-party download( https://dl.bintray.com/boostorg/release/1.67.0/binaries/). This way all the libraries were built correctly and I had no trouble linking to them.
I am struggling with cmake-baed boost linking problem that I searched on stackoverflow, and on other forums but to no avail.
I am compiling a C++ program suite (depending on different libraries, in addition to Boost) on a cluster where Boost is already installed (and I know the full path). After getting weird linking errors for boost with cmake while compiling, I thought of first compiling a very simple boost-cmake example to solve the problem.
The code is given below.
#include <boost/program_options/options_description.hpp>
#include <boost/program_options/option.hpp>
using namespace std;
#include <iostream>
namespace po = boost::program_options;
int main(int argc, char** argv) {
po::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
;
return 0;
}
I am using the following CMakeLists.txt file for building.
cmake_minimum_required(VERSION 2.8)
set(Boost_INCLUDE_DIR /software/apps/boost/1.55.0/build06/include)
set(Boost_LIBRARY_DIR /software/apps/boost/1.55.0/build06/lib)
find_package(Boost COMPONENTS program_options REQUIRED)
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIR})
message("Boost include dir is ${Boost_INCLUDE_DIR}")
message("Boost library dir is ${Boost_LIBRARY_DIR}")
message("Boost libraries are at ${Boost_LIBRARIES}")
add_executable(main main.cpp)
target_link_libraries( main ${Boost_LIBRARIES} )
When I compile using cmake, I get the following output
x_ikrul#ikramu build]$ emacs ../CMakeLists.txt
Display localhost:39.0 unavailable, simulating -nw
[x_ikrul#triolith1 build]$ rm -rf *
[x_ikrul#triolith1 build]$ cmake ..
-- The C compiler identification is GNU 4.7.2
-- The CXX compiler identification is GNU 4.7.2
-- Check for working C compiler: /software/apps/comp_wrapper/gnu/gcc
-- Check for working C compiler: /software/apps/comp_wrapper/gnu/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /software/apps/comp_wrapper/gnu/c++
-- Check for working CXX compiler: /software/apps/comp_wrapper/gnu/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
Boost found.
Found Boost components:
program_options
Boost include dir is /usr/include
Boost library dir is /software/apps/boost/1.55.0/build06/lib
Boost libraries are at optimized;boost_program_options-mt-shared;debug;boost_program_options-mt-shared-debug
-- Configuring done
-- Generating done
-- Build files have been written to: /home/x_ikrul/Downloads/boost_example/build
THE PROBLEM comes when I "make" the code as given below.
x_ikrul#ikramu build]$make
Scanning dependencies of target main
[100%] Building CXX object CMakeFiles/main.dir/main.cpp.o
make[2]: *** No rule to make target `/usr/lib64/lib64/libboost_program_options-mt.so.5', needed by `main'. Stop.
make[1]: *** [CMakeFiles/main.dir/all] Error 2
make: *** [all] Error 2
As you may see, although CMake shows the lib directory for boost to be /software/apps/boost/1.55.0/build06/lib, strangely at linking time, it is referring to a different non-exising directory.
Anybody came across error like this? The cluster is running CentOS release 6.5, the boost (where I am pointing) is 1.55.0 and the cmake I am using is 2.8.8.
You're not setting the hint paths correctly.
From the FindBoost module docs:
This module reads hints about search locations from variables:
BOOST_ROOT - Preferred installation prefix
(or BOOSTROOT)
BOOST_INCLUDEDIR - Preferred include directory e.g. <prefix>/include
BOOST_LIBRARYDIR - Preferred library directory e.g. <prefix>/lib
Boost_NO_SYSTEM_PATHS - Set to ON to disable searching in locations not
specified by these hint variables. Default is OFF.
...
and saves search results persistently in CMake cache entries:
Boost_INCLUDE_DIR - Directory containing Boost headers
Boost_LIBRARY_DIR - Directory containing Boost libraries
So, your lines:
set(Boost_INCLUDE_DIR /software/apps/boost/1.55.0/build06/include)
set(Boost_LIBRARY_DIR /software/apps/boost/1.55.0/build06/lib)
aren't actually setting hint variables - you want to be setting BOOST_INCLUDEDIR and BOOST_LIBRARYDIR; possibly also Boost_NO_SYSTEM_PATHS.
This is best not hard-coded inside your CMakeLists.txt since that's not portable. Rather pass these on the command line when invoking CMake:
cmake . -DBOOST_INCLUDEDIR=/software/apps/boost/1.55.0/build06/include -DBOOST_LIBRARYDIR=/software/apps/boost/1.55.0/build06/lib -DBoost_NO_SYSTEM_PATHS=ON
You can also get a much better idea of what's going on if you set Boost_DEBUG to ON.
As an aside, you shouldn't need the link_directories call since the full paths to the Boost libs are passed in the target_link_libraries call.
This stackoverflow answer suggests adding -DBoost_NO_BOOST_CMAKE=ON on the cmake command line.
It seems to be caused by the fact that some CMake versions do not work well with some Boost versions.
And I agree to what user Fraser said. These lines do not make sense
set(Boost_INCLUDE_DIR /software/apps/boost/1.55.0/build06/include)
set(Boost_LIBRARY_DIR /software/apps/boost/1.55.0/build06/lib)
as those variables are used by CMake to store the result from the Boost search. Read more about it in his answer.