I am trying to use the new Boost.Log library in a project I am working on. The project is built with CMake. I am receiving link errors claiming that the linker has come across undefined references to Boost.Log
Linking CXX executable main
CMakeFiles/main.dir/main.cpp.o: In function `main':
main.cpp:(.text+0x30): undefined reference to `boost::log::v2s_mt_posix::trivial::logger::get()'
I have a simple hello world test that fails with these errors. If I am linking against the Boost.Log libraries what would cause it to generate an undefined reference error?
main.cpp:
#include <boost/log/trivial.hpp>
int main(int argc, char* const argv[]) {
BOOST_LOG_TRIVIAL(info) << "Hello World";
}
CMakeLists.txt:
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
FIND_PACKAGE(Boost 1.54 COMPONENTS log REQUIRED)
FIND_PACKAGE(Threads)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
ADD_EXECUTABLE(main main.cpp)
TARGET_LINK_LIBRARIES(main ${Boost_LOG_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
Edit: verbose output from cmake and make
cmake:
-- [ /usr/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
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:478 ] Boost_USE_MULTITHREADED = TRUE
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:480 ] Boost_USE_STATIC_LIBS =
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:482 ] Boost_USE_STATIC_RUNTIME =
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:484 ] Boost_ADDITIONAL_VERSIONS =
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:486 ] Boost_NO_SYSTEM_PATHS =
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:538 ] Declared as CMake or Environmental Variables:
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:540 ] BOOST_ROOT =
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:542 ] BOOST_INCLUDEDIR =
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:544 ] BOOST_LIBRARYDIR =
-- [ /usr/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
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:639 ] location of version.hpp: /usr/include/boost/version.hpp
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:663 ] version.hpp reveals boost 1.54.0
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:739 ] guessed _boost_COMPILER = -gcc48
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:749 ] _boost_MULTITHREADED = -mt
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:792 ] _boost_RELEASE_ABI_TAG = -
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:794 ] _boost_DEBUG_ABI_TAG = -d
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:842 ] _boost_LIBRARY_SEARCH_DIRS = /usr/lib64;NO_DEFAULT_PATH
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:930 ] Searching for LOG_LIBRARY_RELEASE: boost_log-gcc48-mt-1_54;boost_log-gcc48-mt;boost_log-mt-1_54;boost_log-mt;boost_log
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:966 ] Searching for LOG_LIBRARY_DEBUG: boost_log-gcc48-mt-d-1_54;boost_log-gcc48-mt-d;boost_log-mt-d-1_54;boost_log-mt-d;boost_log-mt;boost_log
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:1017 ] Boost_FOUND = 1
-- Boost version: 1.54.0
-- Found the following Boost libraries:
-- log
-- Configuring done
-- Generating done
-- Build files have been written to: /home/durrw/boost-log-test/build
make:
/usr/bin/cmake -H/home/durrw/boost-log-test -B/home/durrw/boost-log-test/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/durrw/boost-log-test/build/CMakeFiles /home/durrw/boost-log-test/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory `/home/durrw/boost-log-test/build'
make -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/depend
make[2]: Entering directory `/home/durrw/boost-log-test/build'
cd /home/durrw/boost-log-test/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/durrw/boost-log-test /home/durrw/boost-log-test /home/durrw/boost-log-test/build /home/durrw/boost-log-test/build /home/durrw/boost-log-test/build/CMakeFiles/main.dir/DependInfo.cmake --color=
make[2]: Leaving directory `/home/durrw/boost-log-test/build'
make -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/build
make[2]: Entering directory `/home/durrw/boost-log-test/build'
Linking CXX executable main
/usr/bin/cmake -E cmake_link_script CMakeFiles/main.dir/link.txt --verbose=1
/usr/bin/c++ CMakeFiles/main.dir/main.cpp.o -o main -rdynamic -lboost_log -lpthread
CMakeFiles/main.dir/main.cpp.o: In function `main':
main.cpp:(.text+0x39): undefined reference to `boost::log::v2s_mt_posix::trivial::logger::get()'
It looks like it boils down to linking to the shared version of Boost.Log.
There is a bit of detail on the issue in the docs for Boost.Log Your error message mentions the namespace boost::log::v2s_mt_posix and from the docs, this implies the linker is expecting to link to a static version of Boost.Log.
If you want to link to the shared version, it seems you need to define BOOST_LOG_DYN_LINK or BOOST_ALL_DYN_LINK, i.e. in your CMakeLists.txt add:
ADD_DEFINITIONS(-DBOOST_LOG_DYN_LINK)
If you want to link to the static version of Boost.Log, instead you need to add a CMake variable before calling FIND_PACKAGE(Boost ...):
SET(Boost_USE_STATIC_LIBS ON)
FIND_PACKAGE(Boost 1.54 COMPONENTS log REQUIRED)
For further variables which affect how CMake finds Boost, see the docs for FindBoost.
For CMake 3.15 (and some earlier versions) the following appears to be sufficient to build Boost.Log with CMake without the original linker error:
cmake_minimum_required(VERSION 3.15)
project(boost_log_tutorial)
SET(Boost_USE_STATIC_LIBS ON) # link statically
#ADD_DEFINITIONS(-DBOOST_LOG_DYN_LINK) # or, link dynamically
find_package(Boost 1.69.0 COMPONENTS log REQUIRED)
add_executable(boost_log_tutorial main.cpp)
target_link_libraries(boost_log_tutorial Boost::log_setup Boost::log)
The key things seem to be linking against Boost:log_setup and Boost::log, and specifying either static or dynamic linking with SET(Boost_USE_STATIC_LIBS ON) or ADD_DEFINITIONS(-DBOOST_LOG_DYN_LINK).
Also, make sure that the build type (Debug, or Release) for Conan matches the build type for CMake. For example:
$ conan install -s build_type=Debug ..
$ cmake -DCMAKE_BUILD_TYPE=Debug ..
If they mismatch then the link will fail with the same error.
It is Boost_INCLUDE_DIRS not Boost_INCLUDE_DIR.
You could try enable Boost_USE_STATIC_LIBS
Related
I am using the experimental GLM hash features in a CMake project.
Everything works fine unless the project is generated by Clion.
When building the Clion generated project GLM raises the error "GLM_GTX_hash requires C++11 standard library support" (see CMake logs) although C++11 is enabled.
Building the same, clion generated, project from a terminal fails with the same error.
However, when generating and building the project with cmake 'manually' (without Clion even knowing about it) everything works fine. As expected.
GLM is not directly included in the CMakeList. GLFW includes/imports it.
Example CMakeLists.txt
(...)
set(CMAKE_CXX_STANDARD 11)
add_executable(Test main.cpp)
(...)
add_subdirectory("glfw" ${CMAKE_CURRENT_BINARY_DIR}/glfw)
target_include_directories(Test PUBLIC ${GLFW_INCLUDE_DIRS})
target_link_libraries(Test ${GLFW_LIBRARIES} glfw)
Example main.cpp
#define GLM_FORCE_RADIANS
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/hash.hpp>
int main() {
return 0;
}
Clion build output:
/usr/bin/cmake --build /home/lukas/Test/cmake-build-debug --target Test -- -j 2
[ 89%] Built target glfw
Scanning dependencies of target Test
[ 94%] Building CXX object CMakeFiles/Test.dir/main.cpp.o
In file included from /home/lukas/Test/main.cpp:8:
/usr/include/glm/gtx/hash.hpp:46:3: error: "GLM_GTX_hash requires C++11 standard library support"
# error "GLM_GTX_hash requires C++11 standard library support"
^
1 error generated.
make[3]: *** [CMakeFiles/Test.dir/build.make:63: CMakeFiles/Test.dir/main.cpp.o] Error 1
make[2]: *** [CMakeFiles/Makefile2:73: CMakeFiles/Test.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:85: CMakeFiles/Test.dir/rule] Error 2
make: *** [Makefile:118: Test] Error 2
Terminal output (as expected)
$ cmake -H. -Bbuild -G "Unix Makefiles" && cmake --build build
Scanning dependencies of target glfw
[ 5%] Building C object glfw/src/CMakeFiles/glfw.dir/context.c.o
[ 10%] Building C object glfw/src/CMakeFiles/glfw.dir/init.c.o
[ 15%] Building C object glfw/src/CMakeFiles/glfw.dir/input.c.o
[ 21%] Building C object glfw/src/CMakeFiles/glfw.dir/monitor.c.o
[ 26%] Building C object glfw/src/CMakeFiles/glfw.dir/vulkan.c.o
[ 31%] Building C object glfw/src/CMakeFiles/glfw.dir/window.c.o
[ 36%] Building C object glfw/src/CMakeFiles/glfw.dir/x11_init.c.o
[ 42%] Building C object glfw/src/CMakeFiles/glfw.dir/x11_monitor.c.o
[ 47%] Building C object glfw/src/CMakeFiles/glfw.dir/x11_window.c.o
[ 52%] Building C object glfw/src/CMakeFiles/glfw.dir/xkb_unicode.c.o
[ 57%] Building C object glfw/src/CMakeFiles/glfw.dir/posix_time.c.o
[ 63%] Building C object glfw/src/CMakeFiles/glfw.dir/posix_thread.c.o
[ 68%] Building C object glfw/src/CMakeFiles/glfw.dir/glx_context.c.o
[ 73%] Building C object glfw/src/CMakeFiles/glfw.dir/egl_context.c.o
[ 78%] Building C object glfw/src/CMakeFiles/glfw.dir/osmesa_context.c.o
[ 84%] Building C object glfw/src/CMakeFiles/glfw.dir/linux_joystick.c.o
[ 89%] Linking C static library libglfw3.a
[ 89%] Built target glfw
Scanning dependencies of target Test
[ 94%] Building CXX object CMakeFiles/Test.dir/main.cpp.o
[100%] Linking CXX executable Test
[100%] Built target Test
Now I am actually curious about rather I messed up somewhere or if it is simply a bug. And if so, where should I report it?
[Clion/Jetbrains?, GLM?, GLFW?, CMake?]
Thanks in advance
Update
I am using the latest available (for me) builds:
CMake version: 3.14.4
Operating System: Arch Linux 5.0.18-1 x86_64 GNU/Linux
GLFW version/commit: d834f01c
GLM version/commit: fce2abd0
Clion: 2019.1.3
Clion EAP: 2019.2 EAP
Final update / 'Solution'
I just discovered that the problem is Clang, not Clion or anything else.
Clion simply defaulted to Clang (instead of GCC).
There are bug reports for GLM and Clang already existing (with potential fixes!):
https://github.com/g-truc/glm/issues/620
https://github.com/g-truc/glm/issues/646
Thank you very much everyone ~
I've been writing a compiler using LLVM as the backend. The CMake files I've written so far have worked on Linux, but I haven't had any luck on Windows. The project is split into a library and "driver" executable with their own CMakeLists.txt in separate subdirectories.
The top level CMakeLists.txt looks like this:
cmake_minimum_required (VERSION 3.7.0)
project (compiler)
set (CMAKE_CXX_STANDARD 14)
set (CMAKE_CXX_STANDARD_REQUIRED ON)
set (CMAKE_CXX_EXTENSIONS OFF)
find_package (LLVM REQUIRED CONFIG)
message (STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message (STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
include_directories (${LLVM_INCLUDE_DIRS})
add_definitions(${LLVM_DEFINITIONS})
add_subdirectory (Compiler_Lib)
add_subdirectory (Compiler_exe)
The CMakeLists.txt for the library:
cmake_minimum_required (VERSION 3.7.0)
add_library (compiler_lib
AST.cpp
AST.h
parser.cpp
parser.h
scanner.cpp
scanner.h
token.cpp
token.h
visualizer.cpp
visualizer.h
codegen.cpp
codegen.h)
target_include_directories (compiler_lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(compiler_lib LLVM)
And the CMakeLists.txt for the executable (which is where linking to the libraries fails):
cmake_minimum_required (VERSION 3.7.0)
project (compiler_exe)
add_executable (compiler_exe Compiler_exe.cpp getopt.h getopt.cpp)
target_link_libraries (compiler_exe LINK_PUBLIC LLVM compiler_lib)
I run the command "c:\Program Files\CMake\bin\cmake.exe" .. -G"MinGW Makefiles" -DCMAKE_PREFIX_PATH=C:\Users\James\llvm+clang-7.0.0-win64-msvc-release where C:\Users\James\llvm+clang-7.0.0-win64-msvc-release is the path to prebuilt LLVM libraries. However, running mingw32-make afterwards fails with the output
Scanning dependencies of target compiler_lib
[ 10%] Building CXX object Compiler_Lib/CMakeFiles/compiler_lib.dir/AST.cpp.obj
[ 20%] Building CXX object Compiler_Lib/CMakeFiles/compiler_lib.dir/parser.cpp.obj
[ 30%] Building CXX object Compiler_Lib/CMakeFiles/compiler_lib.dir/scanner.cpp.obj
[ 40%] Building CXX object Compiler_Lib/CMakeFiles/compiler_lib.dir/token.cpp.obj
[ 50%] Building CXX object Compiler_Lib/CMakeFiles/compiler_lib.dir/visualizer.cpp.obj
[ 60%] Building CXX object Compiler_Lib/CMakeFiles/compiler_lib.dir/codegen.cpp.obj
[ 70%] Linking CXX static library libcompiler_lib.a
[ 70%] Built target compiler_lib
Scanning dependencies of target compiler_exe
[ 80%] Building CXX object Compiler_exe/CMakeFiles/compiler_exe.dir/Compiler_exe.cpp.obj
[ 90%] Building CXX object Compiler_exe/CMakeFiles/compiler_exe.dir/getopt.cpp.obj
[100%] Linking CXX executable compiler_exe.exe
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: cannot find -lLLVM
collect2.exe: error: ld returned 1 exit status
Compiler_exe\CMakeFiles\compiler_exe.dir\build.make:102: recipe for target 'Compiler_exe/compiler_exe.exe' failed
mingw32-make[2]: *** [Compiler_exe/compiler_exe.exe] Error 1
CMakeFiles\Makefile2:176: recipe for target 'Compiler_exe/CMakeFiles/compiler_exe.dir/all' failed
mingw32-make[1]: *** [Compiler_exe/CMakeFiles/compiler_exe.dir/all] Error 2
Makefile:82: recipe for target 'all' failed
mingw32-make: *** [all] Error 2
This is the first time I've used CMake so I could have missed something obvious, but as I say it seems to work on Linux.
For the linking to succeed two things need to be true:
1) the file libLLVM.a needs to exist
2) that file has to be in a directory in the library search path
There should be a way to get cmake to tell you the list of places it searches for libraries, and you need to find a way to get wherever libLLVM.a exists into that list of dirs.
Apologies for the partial answer, but that's the troubleshooting path...
I'm trying to use the Boost library in my C++ project on Windows using CLion and MinGWMSVC. I downloaded the precompiled binaries here and extracted everything to C:\local\boost_1_69_0_b1_rc3. I setup the following CMakeLists.txt:
cmake_minimum_required(VERSION 3.11.4)
project(BoostTesting)
set(CMAKE_CXX_STANDARD 17)
set(BOOST_ROOT "C:/local/boost_1_69_0_b1_rc3")
set(BOOST_LIBRARYDIR "C:/local/boost_1_69_0_b1_rc3/lib64-msvc-14.1")
set(BOOST_INCLUDEDIR "C:/local/boost_1_69_0_b1_rc3/boost")
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
set(Boost_DEBUG ON)
set(Boost_DETAILED_FAILURE_MSG ON)
set(Boost_COMPILER "-vc141")
set(Boost_ARCHITECTURE "-x64")
find_package(Boost 1.69.0 COMPONENTS filesystem REQUIRED)
if (Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
add_executable(BoostTesting main.cpp)
target_link_libraries(BoostTesting ${Boost_LIBRARIES})
endif ()
Using CMake's FindBoost debug mode (Boost_DEBUG) I got the following output:
C:\Users\User\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\183.4284.104\bin\cmake\win\bin\cmake.exe -DCMAKE_BUILD_TYPE=Debug "-DCMAKE_MAKE_PROGRAM=C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/mingw32-make.exe" "-DCMAKE_C_COMPILER=C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/x86_64-w64-mingw32-gcc.exe" "-DCMAKE_CXX_COMPILER=C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/x86_64-w64-mingw32-g++.exe" -G "CodeBlocks - MinGW Makefiles" D:\Cpp\BoostTesting
-- The C compiler identification is GNU 8.1.0
-- The CXX compiler identification is GNU 8.1.0
-- Check for working C compiler: C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/x86_64-w64-mingw32-gcc.exe
-- Check for working C compiler: C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/x86_64-w64-mingw32-gcc.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/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/x86_64-w64-mingw32-g++.exe
-- Check for working CXX compiler: C:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/x86_64-w64-mingw32-g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Warning (dev) at CMakeLists.txt:18 (find_package):
Policy CMP0074 is not set: find_package uses <PackageName>_ROOT variables.
Run "cmake --help-policy CMP0074" for policy details. Use the cmake_policy
command to set the policy and suppress this warning.
Environment variable Boost_ROOT is set to:
C:\local\boost_1_68_0\boost
For compatibility, CMake is ignoring the variable.
This warning is for project developers. Use -Wno-dev to suppress it.
-- [ C:/Users/User/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/183.4284.104/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:1125 ] _boost_TEST_VERSIONS =
-- [ C:/Users/User/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/183.4284.104/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:1127 ] Boost_USE_MULTITHREADED = ON
-- [ C:/Users/User/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/183.4284.104/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:1129 ] Boost_USE_STATIC_LIBS = ON
-- [ C:/Users/User/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/183.4284.104/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:1131 ] Boost_USE_STATIC_RUNTIME = OFF
-- [ C:/Users/User/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/183.4284.104/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:1133 ] Boost_ADDITIONAL_VERSIONS =
-- [ C:/Users/User/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/183.4284.104/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:1135 ] Boost_NO_SYSTEM_PATHS =
-- [ C:/Users/User/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/183.4284.104/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:1203 ] Declared as CMake or Environmental Variables:
-- [ C:/Users/User/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/183.4284.104/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:1205 ] BOOST_ROOT = C:/local/boost_1_69_0_b1_rc3
-- [ C:/Users/User/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/183.4284.104/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:1207 ] BOOST_INCLUDEDIR = C:/local/boost_1_69_0_b1_rc3/boost
-- [ C:/Users/User/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/183.4284.104/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:1209 ] BOOST_LIBRARYDIR = C:/local/boost_1_69_0_b1_rc3/lib64-msvc-14.1
-- [ C:/Users/User/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/183.4284.104/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:1211 ] _boost_TEST_VERSIONS =
-- [ C:/Users/User/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/183.4284.104/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:1286 ] Include debugging info:
-- [ C:/Users/User/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/183.4284.104/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:1288 ] _boost_INCLUDE_SEARCH_DIRS = C:/local/boost_1_69_0_b1_rc3/boost;C:/local/boost_1_69_0_b1_rc3/include;C:/local/boost_1_69_0_b1_rc3;PATHS;C:/boost/include;C:/boost;/sw/local/include
-- [ C:/Users/User/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/183.4284.104/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:1290 ] _boost_PATH_SUFFIXES =
-- [ C:/Users/User/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/183.4284.104/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:1310 ] location of version.hpp: C:/local/boost_1_69_0_b1_rc3/boost/version.hpp
-- [ C:/Users/User/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/183.4284.104/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:1334 ] version.hpp reveals boost 1.69.0
-- [ C:/Users/User/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/183.4284.104/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:1410 ] using user-specified Boost_COMPILER = -vc141
-- [ C:/Users/User/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/183.4284.104/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:1430 ] _boost_MULTITHREADED = -mt
-- [ C:/Users/User/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/183.4284.104/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:1506 ] _boost_RELEASE_ABI_TAG = -
-- [ C:/Users/User/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/183.4284.104/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:1508 ] _boost_DEBUG_ABI_TAG = -d
-- [ C:/Users/User/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/183.4284.104/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:1571 ] _boost_LIBRARY_SEARCH_DIRS_RELEASE = C:/local/boost_1_69_0_b1_rc3/lib64-msvc-14.1;C:/local/boost_1_69_0_b1_rc3/lib;C:/local/boost_1_69_0_b1_rc3/stage/lib;C:/local/boost_1_69_0_b1_rc3/lib;C:/local/boost_1_69_0_b1_rc3/../lib;C:/local/boost_1_69_0_b1_rc3/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib_boost_LIBRARY_SEARCH_DIRS_DEBUG = C:/local/boost_1_69_0_b1_rc3/lib64-msvc-14.1;C:/local/boost_1_69_0_b1_rc3/lib;C:/local/boost_1_69_0_b1_rc3/stage/lib;C:/local/boost_1_69_0_b1_rc3/lib;C:/local/boost_1_69_0_b1_rc3/../lib;C:/local/boost_1_69_0_b1_rc3/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib
CMake Warning at C:/Users/User/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/183.4284.104/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:847 (message):
New Boost version may have incorrect or missing dependencies and imported
targets
Call Stack (most recent call first):
C:/Users/User/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/183.4284.104/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:963 (_Boost_COMPONENT_DEPENDENCIES)
C:/Users/User/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/183.4284.104/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:1622 (_Boost_MISSING_DEPENDENCIES)
CMakeLists.txt:18 (find_package)
CMake Warning at C:/Users/User/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/183.4284.104/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:847 (message):
New Boost version may have incorrect or missing dependencies and imported
targets
Call Stack (most recent call first):
C:/Users/User/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/183.4284.104/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:963 (_Boost_COMPONENT_DEPENDENCIES)
C:/Users/User/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/183.4284.104/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:1622 (_Boost_MISSING_DEPENDENCIES)
CMakeLists.txt:18 (find_package)
-- [ C:/Users/User/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/183.4284.104/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:1760 ] Searching for FILESYSTEM_LIBRARY_RELEASE: libboost_filesystem-vc141-mt-1_69;libboost_filesystem-vc141-mt;libboost_filesystem-mt-1_69;libboost_filesystem-mt;libboost_filesystem
-- [ C:/Users/User/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/183.4284.104/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:1813 ] Searching for FILESYSTEM_LIBRARY_DEBUG: libboost_filesystem-vc141-mt-d-1_69;libboost_filesystem-vc141-mt-d;libboost_filesystem-mt-d-1_69;libboost_filesystem-mt-d;libboost_filesystem-mt;libboost_filesystem
-- [ C:/Users/User/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/183.4284.104/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:1760 ] Searching for SYSTEM_LIBRARY_RELEASE: libboost_system-vc141-mt-1_69;libboost_system-vc141-mt;libboost_system-mt-1_69;libboost_system-mt;libboost_system
-- [ C:/Users/User/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/183.4284.104/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:1813 ] Searching for SYSTEM_LIBRARY_DEBUG: libboost_system-vc141-mt-d-1_69;libboost_system-vc141-mt-d;libboost_system-mt-d-1_69;libboost_system-mt-d;libboost_system-mt;libboost_system
-- [ C:/Users/User/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/183.4284.104/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:1887 ] Boost_FOUND = 1
CMake Error at C:/Users/User/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/183.4284.104/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:2048 (message):
Unable to find the requested Boost libraries.
Boost version: 1.69.0
Boost include path: C:/local/boost_1_69_0_b1_rc3
Could not find the following static Boost libraries:
boost_filesystem
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:18 (find_package)
-- Configuring incomplete, errors occurred!
See also "D:/Cpp/BoostTesting/cmake-build-debug/CMakeFiles/CMakeOutput.log".
[Failed to reload]
CMake is looking for those specific files but I noticed that the -x64 indication is not part of the searched file names. My directory only contains 64-bit libraries:
Why is the Boost_ARCHITECTURE environment variable ignored? I expect it to add the missing -x64 to the searched file names. If I manually rename the libboost_filesystem-vc141-mt*.lib files they can be found by CMake. However, if I compile and link my simple main.cpp I'm getting a linker error:
====================[ Build | BoostTesting | Debug ]============================
C:\Users\User\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\183.4284.104\bin\cmake\win\bin\cmake.exe --build D:\Cpp\BoostTesting\cmake-build-debug --target BoostTesting -- -j 4
Scanning dependencies of target BoostTesting
[ 50%] Building CXX object CMakeFiles/BoostTesting.dir/main.cpp.obj
[100%] Linking CXX executable BoostTesting.exe
CMakeFiles\BoostTesting.dir/objects.a(main.cpp.obj): In function `boost::filesystem::path_traits::convert(char const*, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&)':
C:/local/boost_1_69_0_b1_rc3/boost/filesystem/path.hpp:997: undefined reference to `boost::filesystem::path::codecvt()'
C:/local/boost_1_69_0_b1_rc3/boost/filesystem/path.hpp:997: undefined reference to `boost::filesystem::path_traits::convert(char const*, char const*, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&, std::codecvt<wchar_t, char, int> const&)'
CMakeFiles\BoostTesting.dir/objects.a(main.cpp.obj): In function `boost::filesystem::file_size(boost::filesystem::path const&)':
C:/local/boost_1_69_0_b1_rc3/boost/filesystem/operations.hpp:616: undefined reference to `boost::filesystem::detail::file_size(boost::filesystem::path const&, boost::system::error_code*)'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [CMakeFiles\BoostTesting.dir\build.make:88: BoostTesting.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:72: CMakeFiles/BoostTesting.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:84: CMakeFiles/BoostTesting.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:117: BoostTesting] Error 2
main.cpp source code:
#include <iostream>
#include <boost/filesystem.hpp>
using namespace boost::filesystem;
int main(int argc, char *argv[]) {
if (argc < 2) {
std::cout << "Usage: tut1 path\n";
return 1;
}
std::cout << argv[1] << " " << file_size(argv[1]) << '\n';
return 0;
}
I'm pretty sure renaming the files is not the proper way of doing it. But even this way it doesn't work. What am I doing wrong and how do you properly use Boost in a simple C++ project like this one?
I believe find_package(Boost ...) has failed in your case as it won't be able to find the REQUIRED filesystem library for 64-bit GCC.
Make sure you have the GCC build of Boost available as well, because now you're only showing the V++ libraries.
You got CMake warning
New Boost version may have incorrect or missing dependencies and imported targets
because that CMake version does not prepared for boost 1.69 (Maybe latest CMake does...).
So CMake tries its best to recognize that version, so it still may work (see point 3 below).
#Felix Natter correctly pointed out above that Boost_ARCHITECTURE is handled only from CMake 3.13.
You can make it work without manual renaming, without GCC or MINGW, if you rebuild your boost with one of the file naming "layouts", your CMake recognizes.
(From your debug log these ones:
libboost_<module name>-<toolset>[-mt]-<ABI tag>-<boost version>
libboost_<module name>-<toolset>[-mt]-<ABI tag>
libboost_<module name>[-mt]-<ABI tag>-<boost version>
libboost_<module name>[-mt]
libboost_<module name>)
Unfortunately only the system layout matches, which means you need to separate Debug and Release builds in different "lib" folders. For explanation about the "layout" parameter see here.
So rebuild boost by specifying the --layout=system parameter, and also decide the variant by specifying variant=debug or variant=release.
As a starting point, on SF you can find the build log file:
https://sourceforge.net/projects/boost/files/boost-binaries/1.69.0/boost_1_69_0-64bitlog.txt/download
The last build "entry" in the file is for vc141, which is your version:
b2 -j%NUMBER_OF_PROCESSORS% --without-mpi --build-type=complete toolset=msvc-14.1 address-model=64 architecture=x86 --prefix=.\ --libdir=lib64-msvc-14.1 --includedir=garbage_headers install
Go to your boost source root and do > bootstrap first.
Make sure msvc-14.1 was detected.
Now build:
> b2 -a -j%NUMBER_OF_PROCESSORS% --without-mpi --with-filesystem toolset=msvc-14.1 address-model=64 architecture=x86 variant=debug --layout=system --prefix=C:\boost_build\debug
Do it for Release in a different target directory.
Change --prefix according to your needs. You may also specify --libdir and --includedir if the default is not good for you.
Of course, probably you need to modify your CMakeList file so that it can use both the Debug and Release variants...
So the best is to use a CMake version, which recognizes boost ver 1.69, and/or get a CMake-based version of boost, which includes 1.69.
set(Boost_ARCHITECTURE "-x64")
only works with cmake >= 3.13 [1] [2]. If you cannot upgrade to cmake 3.13+,
you can work around with:
set(CMAKE_CXX_COMPILER_ARCHITECTURE_ID, "x64")
(not sure under what conditions this is set automatically)
[1] https://cmake.org/cmake/help/v3.12/module/FindBoost.html
[2] https://cmake.org/cmake/help/v3.13/module/FindBoost.html
It turns out it works when using the MinGW distribution with built-in Boost.
CMakeLists.txt:
cmake_minimum_required(VERSION 3.11.4)
project(BoostTesting)
set(CMAKE_CXX_STANDARD 17)
if(WIN32)
set(BOOST_ROOT "C:/MinGW")
endif ()
find_package(Boost 1.67.0 COMPONENTS filesystem REQUIRED)
if (Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
add_executable(BoostTesting main.cpp)
target_link_libraries(BoostTesting ${Boost_LIBRARIES})
endif ()
main.cpp output:
D:\Cpp\BoostTesting\cmake-build-debug\BoostTesting.exe
Usage: tut1 path
Process finished with exit code 1
It compiled and linked successfully.
I have a library that is a Python extension (pyd) and to be able to debug it I need to compile with Multi-threaded DLL (/MD) Runtime Libraries.
This works great until I injected a Boost dependency.
But first time I call a Boost function the code crashes with a read access violation exception.
After some investigation it turns out cmake find_package(Boost) pulls in the boost libraries build with a different run-time library i.e.boost_filesystem-vc140-mt-gd.lib
I have put this in an easy test case.
Build boost using vcpkg:
git clone https://github.com/Microsoft/vcpkg.git
.\bootstrap-vcpkg.bat
vcpkg install boost
This only generates the -mt and -md-gd boost libraries.
CMakeLists.txt
cmake_minimum_required (VERSION 3.6.3)
project (FindMDBoost CXX)
set (CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MD")
file (GLOB_RECURSE SOURCES "source.cpp")
set(Boost_DEBUG ON)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTI_THREADED OFF)
find_package(Boost COMPONENTS filesystem REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
add_executable(testcode ${SOURCES})
target_link_libraries(testcode ${Boost_LIBRARIES})
source.cpp
#include <boost/filesystem/path.hpp>
int main()
{
auto path = boost::filesystem::path("c:\\"); // Call Boost to see if it crashes
}
Run cmake:
mkdir build; cd build
cmake .. "-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake"
As you can see in the output cmake still tried to find the wrong run time and ignores my Boost_USE_STATIC_LIBS and Boost_USE_MULTI_THREADED flags!
-- [ C:/install/cmake-3.10.2-win64-x64/share/cmake-3.10/Modules/FindBoost.cmake:1078 ] _boost_TEST_VERSIONS = 1.65.1;1.65.0;1.65;1.64.0;1.64;1.63.0;1.63;1.62.0;1.62;1.61.0;1.61;1.60.0;1.60;1.59.0;1.59;1.58.0;1.58;1.57.0;1.57;1.56.0;1.56;1.55.0;1.55;1.54.0;1.54;1.53.0;1.53;1.52.0;1.52;1.51.0;1.51;1.50.0;1.50;1.49.0;1.49;1.48.0;1.48;1.47.0;1.47;1.46.1;1.46.0;1.46;1.45.0;1.45;1.44.0;1.44;1.43.0;1.43;1.42.0;1.42;1.41.0;1.41;1.40.0;1.40;1.39.0;1.39;1.38.0;1.38;1.37.0;1.37;1.36.1;1.36.0;1.36;1.35.1;1.35.0;1.35;1.34.1;1.34.0;1.34;1.33.1;1.33.0;1.33
-- [ C:/install/cmake-3.10.2-win64-x64/share/cmake-3.10/Modules/FindBoost.cmake:1080 ] Boost_USE_MULTITHREADED = TRUE
-- [ C:/install/cmake-3.10.2-win64-x64/share/cmake-3.10/Modules/FindBoost.cmake:1082 ] Boost_USE_STATIC_LIBS =
-- [ C:/install/cmake-3.10.2-win64-x64/share/cmake-3.10/Modules/FindBoost.cmake:1084 ] Boost_USE_STATIC_RUNTIME =
-- [ C:/install/cmake-3.10.2-win64-x64/share/cmake-3.10/Modules/FindBoost.cmake:1086 ] Boost_ADDITIONAL_VERSIONS =
-- [ C:/install/cmake-3.10.2-win64-x64/share/cmake-3.10/Modules/FindBoost.cmake:1088 ] Boost_NO_SYSTEM_PATHS =
-- [ C:/install/cmake-3.10.2-win64-x64/share/cmake-3.10/Modules/FindBoost.cmake:1156 ] Declared as CMake or Environmental Variables:
-- [ C:/install/cmake-3.10.2-win64-x64/share/cmake-3.10/Modules/FindBoost.cmake:1158 ] BOOST_ROOT =
-- [ C:/install/cmake-3.10.2-win64-x64/share/cmake-3.10/Modules/FindBoost.cmake:1160 ] BOOST_INCLUDEDIR =
-- [ C:/install/cmake-3.10.2-win64-x64/share/cmake-3.10/Modules/FindBoost.cmake:1162 ] BOOST_LIBRARYDIR =
-- [ C:/install/cmake-3.10.2-win64-x64/share/cmake-3.10/Modules/FindBoost.cmake:1164 ] _boost_TEST_VERSIONS = 1.65.1;1.65.0;1.65;1.64.0;1.64;1.63.0;1.63;1.62.0;1.62;1.61.0;1.61;1.60.0;1.60;1.59.0;1.59;1.58.0;1.58;1.57.0;1.57;1.56.0;1.56;1.55.0;1.55;1.54.0;1.54;1.53.0;1.53;1.52.0;1.52;1.51.0;1.51;1.50.0;1.50;1.49.0;1.49;1.48.0;1.48;1.47.0;1.47;1.46.1;1.46.0;1.46;1.45.0;1.45;1.44.0;1.44;1.43.0;1.43;1.42.0;1.42;1.41.0;1.41;1.40.0;1.40;1.39.0;1.39;1.38.0;1.38;1.37.0;1.37;1.36.1;1.36.0;1.36;1.35.1;1.35.0;1.35;1.34.1;1.34.0;1.34;1.33.1;1.33.0;1.33
-- [ C:/install/cmake-3.10.2-win64-x64/share/cmake-3.10/Modules/FindBoost.cmake:1263 ] location of version.hpp: C:/dev/vcpkg/installed/x86-windows/include/boost/version.hpp
-- [ C:/install/cmake-3.10.2-win64-x64/share/cmake-3.10/Modules/FindBoost.cmake:1287 ] version.hpp reveals boost 1.66.0
-- [ C:/install/cmake-3.10.2-win64-x64/share/cmake-3.10/Modules/FindBoost.cmake:1363 ] using user-specified Boost_COMPILER = -vc140
-- [ C:/install/cmake-3.10.2-win64-x64/share/cmake-3.10/Modules/FindBoost.cmake:1383 ] _boost_MULTITHREADED = -mt
-- [ C:/install/cmake-3.10.2-win64-x64/share/cmake-3.10/Modules/FindBoost.cmake:1427 ] _boost_RELEASE_ABI_TAG = -
-- [ C:/install/cmake-3.10.2-win64-x64/share/cmake-3.10/Modules/FindBoost.cmake:1429 ] _boost_DEBUG_ABI_TAG = -gd
-- [ C:/install/cmake-3.10.2-win64-x64/share/cmake-3.10/Modules/FindBoost.cmake:1491 ] _boost_LIBRARY_SEARCH_DIRS_RELEASE = C:/dev/vcpkg/installed/x86-windows/lib;NO_DEFAULT_PATH;NO_CMAKE_FIND_ROOT_PATH_boost_LIBRARY_SEARCH_DIRS_DEBUG = C:/dev/vcpkg/installed/x86-windows/debug/lib;NO_DEFAULT_PATH;NO_CMAKE_FIND_ROOT_PATH
-- [ C:/install/cmake-3.10.2-win64-x64/share/cmake-3.10/Modules/FindBoost.cmake:1641 ] Searching for FILESYSTEM_LIBRARY_RELEASE: boost_filesystem-vc140-mt-1_66;boost_filesystem-vc140-mt;boost_filesystem-mt-1_66;boost_filesystem-mt;boost_filesystem
-- [ C:/install/cmake-3.10.2-win64-x64/share/cmake-3.10/Modules/FindBoost.cmake:380 ] Boost_LIBRARY_DIR_RELEASE = C:/dev/vcpkg/installed/x86-windows/lib _boost_LIBRARY_SEARCH_DIRS_RELEASE = C:/dev/vcpkg/installed/x86-windows/lib;NO_DEFAULT_PATH;NO_CMAKE_FIND_ROOT_PATH
-- [ C:/install/cmake-3.10.2-win64-x64/share/cmake-3.10/Modules/FindBoost.cmake:1692 ] Searching for FILESYSTEM_LIBRARY_DEBUG: boost_filesystem-vc140-mt-gd-1_66;boost_filesystem-vc140-mt-gd;boost_filesystem-mt-gd-1_66;boost_filesystem-mt-gd;boost_filesystem-mt;boost_filesystem
-- [ C:/install/cmake-3.10.2-win64-x64/share/cmake-3.10/Modules/FindBoost.cmake:380 ] Boost_LIBRARY_DIR_DEBUG = C:/dev/vcpkg/installed/x86-windows/debug/lib _boost_LIBRARY_SEARCH_DIRS_DEBUG = C:/dev/vcpkg/installed/x86-windows/debug/lib;NO_DEFAULT_PATH;NO_CMAKE_FIND_ROOT_PATH
-- [ C:/install/cmake-3.10.2-win64-x64/share/cmake-3.10/Modules/FindBoost.cmake:1641 ] Searching for SYSTEM_LIBRARY_RELEASE: boost_system-vc140-mt-1_66;boost_system-vc140-mt;boost_system-mt-1_66;boost_system-mt;boost_system
-- [ C:/install/cmake-3.10.2-win64-x64/share/cmake-3.10/Modules/FindBoost.cmake:380 ] Boost_LIBRARY_DIR_RELEASE = C:/dev/vcpkg/installed/x86-windows/lib _boost_LIBRARY_SEARCH_DIRS_RELEASE = C:/dev/vcpkg/installed/x86-windows/lib;NO_DEFAULT_PATH;NO_CMAKE_FIND_ROOT_PATH
-- [ C:/install/cmake-3.10.2-win64-x64/share/cmake-3.10/Modules/FindBoost.cmake:1692 ] Searching for SYSTEM_LIBRARY_DEBUG: boost_system-vc140-mt-gd-1_66;boost_system-vc140-mt-gd;boost_system-mt-gd-1_66;boost_system-mt-gd;boost_system-mt;boost_system
-- [ C:/install/cmake-3.10.2-win64-x64/share/cmake-3.10/Modules/FindBoost.cmake:380 ] Boost_LIBRARY_DIR_DEBUG = C:/dev/vcpkg/installed/x86-windows/debug/lib _boost_LIBRARY_SEARCH_DIRS_DEBUG = C:/dev/vcpkg/installed/x86-windows/debug/lib;NO_DEFAULT_PATH;NO_CMAKE_FIND_ROOT_PATH
-- [ C:/install/cmake-3.10.2-win64-x64/share/cmake-3.10/Modules/FindBoost.cmake:1767 ] Boost_FOUND = 1
-- Boost version: 1.66.0
-- Found the following Boost libraries:
-- filesystem
-- system
-- Configuring done
-- Generating done
-- Build files have been written to: C:/dev/cpptests/FindMDBoost/build
Here is the output from the linking phase.
Update: I build the boost libraries from scratch and the code stopped crashing. So this seems to be a vcpkg issue that is does not build the version of boost I need.
b2 runtime-link=shared -j16
My new CmakeList.txt file
cmake_minimum_required (VERSION 3.6.3)
project (FindMDBoost CXX)
set (CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MD")
file (GLOB_RECURSE SOURCES "source.cpp")
include_directories(C:/dev/boost/boost_1_66_0)
link_directories("C:/dev/boost/boost_1_66_0/stage/lib")
add_executable(testcode ${SOURCES})
target_link_libraries(testcode libboost_filesystem-vc141-mt-x32-1_66.lib)
I believe the issue just has to do with how you tell vcpkg to build boost when installing it. You can specify static or dynamic linking by specifying what they call triplets.
So for you: vcpkg install boost --triplet x64-windows-static
This will build the boost libraries for use with static linking.
The version of the library with an -mt is the correct one for linking to /MD ; confusingly the static library would have an s but does not seem what you want from the remarks at the beginning. You were loading the mt-gd versions which are just the debug versions of these libraries; I suppose they expect the calling python to be the debug version as well.
I am trying to install and use Boost 1.60.0 in my new C++ project. (I use Ubuntu, CLion and CMake for developing and building).
What have I done?
I downloaded Boost from the link provided on the website.
Extracted into /devenv/boost160 (/devenv/boost160 is the root, after I renamed the original folder)
I ran ./bootstrap.sh from /devenv/boost160 (everything went ok; according to their official documentation, running this without arguments, takes the output into /usr/local) and it went smoothly.
I created a CLion project and added the following to CMakeLists.txt.
set(BOOST_ROOT /usr/local/include/boost)
set(BOOST_LIBRARYDIR /usr/local/lib)
set(Boost_USE_MULTITHREAD ON)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_DEBUG ON)
find_package(Boost 1.60.0 REQUIRED COMPONENTS asio date_time)
IF (Boost_FOUND)
include_directories(${Boost_INCLUDE_DIR})
endif()
I ran the CLion's Build command and I got the following output, basically saying that it's unable to find boost_asio.
/devenv/clion-1.1/bin/cmake/bin/cmake --build /home/victor/.clion11/system/cmake/generated/50ae3d2f/50ae3d2f/Debug0 --target all -- -j 8
-- [ /devenv/clion-1.1/bin/cmake/share/cmake-3.3/Modules/FindBoost.cmake:549 ] _boost_TEST_VERSIONS =
-- [ /devenv/clion-1.1/bin/cmake/share/cmake-3.3/Modules/FindBoost.cmake:551 ] Boost_USE_MULTITHREADED = TRUE
-- [ /devenv/clion-1.1/bin/cmake/share/cmake-3.3/Modules/FindBoost.cmake:553 ] Boost_USE_STATIC_LIBS = ON
-- [ /devenv/clion-1.1/bin/cmake/share/cmake-3.3/Modules/FindBoost.cmake:555 ] Boost_USE_STATIC_RUNTIME = ON
-- [ /devenv/clion-1.1/bin/cmake/share/cmake-3.3/Modules/FindBoost.cmake:557 ] Boost_ADDITIONAL_VERSIONS =
-- [ /devenv/clion-1.1/bin/cmake/share/cmake-3.3/Modules/FindBoost.cmake:559 ] Boost_NO_SYSTEM_PATHS =
-- [ /devenv/clion-1.1/bin/cmake/share/cmake-3.3/Modules/FindBoost.cmake:611 ] Declared as CMake or Environmental Variables:
-- [ /devenv/clion-1.1/bin/cmake/share/cmake-3.3/Modules/FindBoost.cmake:613 ] BOOST_ROOT = /usr/local/include/boost
-- [ /devenv/clion-1.1/bin/cmake/share/cmake-3.3/Modules/FindBoost.cmake:615 ] BOOST_INCLUDEDIR =
-- [ /devenv/clion-1.1/bin/cmake/share/cmake-3.3/Modules/FindBoost.cmake:617 ] BOOST_LIBRARYDIR = /usr/local/lib
-- [ /devenv/clion-1.1/bin/cmake/share/cmake-3.3/Modules/FindBoost.cmake:619 ] _boost_TEST_VERSIONS =
-- [ /devenv/clion-1.1/bin/cmake/share/cmake-3.3/Modules/FindBoost.cmake:712 ] location of version.hpp: /usr/local/include/boost/version.hpp
-- [ /devenv/clion-1.1/bin/cmake/share/cmake-3.3/Modules/FindBoost.cmake:736 ] version.hpp reveals boost 1.60.0
-- [ /devenv/clion-1.1/bin/cmake/share/cmake-3.3/Modules/FindBoost.cmake:822 ] guessed _boost_COMPILER = -gcc48
-- [ /devenv/clion-1.1/bin/cmake/share/cmake-3.3/Modules/FindBoost.cmake:832 ] _boost_MULTITHREADED = -mt
-- [ /devenv/clion-1.1/bin/cmake/share/cmake-3.3/Modules/FindBoost.cmake:875 ] _boost_RELEASE_ABI_TAG = -s
-- [ /devenv/clion-1.1/bin/cmake/share/cmake-3.3/Modules/FindBoost.cmake:877 ] _boost_DEBUG_ABI_TAG = -sd
-- [ /devenv/clion-1.1/bin/cmake/share/cmake-3.3/Modules/FindBoost.cmake:931 ] _boost_LIBRARY_SEARCH_DIRS_RELEASE = /usr/lib/x86_64-linux-gnu;NO_DEFAULT_PATH;NO_CMAKE_FIND_ROOT_PATH_boost_LIBRARY_SEARCH_DIRS_DEBUG = /usr/lib/x86_64-linux-gnu;NO_DEFAULT_PATH;NO_CMAKE_FIND_ROOT_PATH
-- [ /devenv/clion-1.1/bin/cmake/share/cmake-3.3/Modules/FindBoost.cmake:1043 ] Searching for ASIO_LIBRARY_RELEASE: boost_asio-gcc48-mt-s-1_60;boost_asio-gcc48-mt-s;boost_asio-mt-s-1_60;boost_asio-mt-s;boost_asio
-- [ /devenv/clion-1.1/bin/cmake/share/cmake-3.3/Modules/FindBoost.cmake:343 ] Boost_LIBRARY_DIR_RELEASE = /usr/lib/x86_64-linux-gnu _boost_LIBRARY_SEARCH_DIRS_RELEASE = /usr/lib/x86_64-linux-gnu;NO_DEFAULT_PATH;NO_CMAKE_FIND_ROOT_PATH
-- [ /devenv/clion-1.1/bin/cmake/share/cmake-3.3/Modules/FindBoost.cmake:1085 ] Searching for ASIO_LIBRARY_DEBUG: boost_asio-gcc48-mt-sd-1_60;boost_asio-gcc48-mt-sd;boost_asio-mt-sd-1_60;boost_asio-mt-sd;boost_asio-mt;boost_asio
-- [ /devenv/clion-1.1/bin/cmake/share/cmake-3.3/Modules/FindBoost.cmake:343 ] Boost_LIBRARY_DIR_DEBUG = /usr/lib/x86_64-linux-gnu _boost_LIBRARY_SEARCH_DIRS_DEBUG = /usr/lib/x86_64-linux-gnu;NO_DEFAULT_PATH;NO_CMAKE_FIND_ROOT_PATH
-- [ /devenv/clion-1.1/bin/cmake/share/cmake-3.3/Modules/FindBoost.cmake:1043 ] Searching for DATE_TIME_LIBRARY_RELEASE: boost_date_time-gcc48-mt-s-1_60;boost_date_time-gcc48-mt-s;boost_date_time-mt-s-1_60;boost_date_time-mt-s;boost_date_time
-- [ /devenv/clion-1.1/bin/cmake/share/cmake-3.3/Modules/FindBoost.cmake:343 ] Boost_LIBRARY_DIR_RELEASE = /usr/lib/x86_64-linux-gnu _boost_LIBRARY_SEARCH_DIRS_RELEASE = /usr/lib/x86_64-linux-gnu;NO_DEFAULT_PATH;NO_CMAKE_FIND_ROOT_PATH
-- [ /devenv/clion-1.1/bin/cmake/share/cmake-3.3/Modules/FindBoost.cmake:1085 ] Searching for DATE_TIME_LIBRARY_DEBUG: boost_date_time-gcc48-mt-sd-1_60;boost_date_time-gcc48-mt-sd;boost_date_time-mt-sd-1_60;boost_date_time-mt-sd;boost_date_time-mt;boost_date_time
-- [ /devenv/clion-1.1/bin/cmake/share/cmake-3.3/Modules/FindBoost.cmake:343 ] Boost_LIBRARY_DIR_DEBUG = /usr/lib/x86_64-linux-gnu _boost_LIBRARY_SEARCH_DIRS_DEBUG = /usr/lib/x86_64-linux-gnu;NO_DEFAULT_PATH;NO_CMAKE_FIND_ROOT_PATH
-- [ /devenv/clion-1.1/bin/cmake/share/cmake-3.3/Modules/FindBoost.cmake:1151 ] Boost_FOUND = 1
CMake Error at /devenv/clion-1.1/bin/cmake/share/cmake-3.3/Modules/FindBoost.cmake:1245 (message):
Unable to find the requested Boost libraries.
Boost version: 1.60.0
Boost include path: /usr/local/include
Could not find the following static Boost libraries:
boost_asio
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:12 (find_package)
-- Configuring incomplete, errors occurred!
See also "/home/victor/.clion11/system/cmake/generated/50ae3d2f/50ae3d2f/Debug0/CMakeFiles/CMakeOutput.log".
make: *** [cmake_check_build_system] Error 1
How can I use Boost 1.60.0 in my project given my configuration? Thank you!
Boost.Asio is a header-only library. The standard CMake function to locate Boost components (FindBoost.cmake) considers only components with pre-built libraries as components, assuming that the header-only components are installed completed with the rest of Boost headers. So you should use find_package(Boost 1.60.0 REQUIRED date_time) (date_time actually has pre-built library and can be located by the FindBoost.cmake).
I'd say that FindBoost.cmake could be enhanced to hide difference between header-only libraries and the real, pre-built ones for application developers. But right now it's the responsibility of the latters.
Edit Regarding the error with system_category: you need Boost.System library as well, so the find_package invocation should look like find_package(Boost 1.60.0 REQUIRED date_time system) and then use Boost_SYSTEM_LIBRARY in target_link_libraries. Unfortunately it seems that Boost still uses it's own implementation of system_category while the latter was standardized in C++11