Reputation: 5042
I have this cmake file:
cmake_minimum_required(VERSION 3.6)
find_package(Boost 1.54.0 REQUIRED COMPONENTS log)
add_executable(TestProject main.cpp)
target_include_directories(TestProject PUBLIC ${Boost_INCLUDE_DIRS})
target_link_libraries(TestProject Boost::log)
add_definitions("-DBOOST_ALL_NO_LIB") # Disable boost auto-linking.
add_definitions("-DBOOST_LOG_DYN_LINK") # Avoid linking errors with boost::log
If I build it using Visual Studio as my generator from a Visual-Studio developer console, I can build just fine. However in my MinGW32 environment I get linker errors. I can confirm that boost is installed in my mingw32 environment and is working well for other projects (which use other boost components).
stewart@PC-1234 MINGW32 ~/src/testproj/buildmsys
$ tree /mingw32 -f | grep libboost_log
│ ├── /mingw32/bin/libboost_log_setup-mt.dll
│ ├── /mingw32/bin/libboost_log-mt.dll
│ ├── /mingw32/lib/libboost_log_setup-mt.a
│ ├── /mingw32/lib/libboost_log_setup-mt.dll.a
│ ├── /mingw32/lib/libboost_log-mt.a
│ ├── /mingw32/lib/libboost_log-mt.dll.a
I build with:
$ mkdir buildmsys && cd buildmsys
$ cmake .. -GNinja
$ cmake --build .
And here is the output
stewart@PC-1234 MINGW32 ~/src/TestProject/buildmsys
$ cmake .. -GNinja
-- Boost version: 1.63.0
-- Found the following Boost libraries:
-- log
-- date_time
-- log_setup
-- system
-- filesystem
-- thread
-- regex
-- chrono
-- atomic
-- Configuring done
-- Generating done
-- Build files have been written to:
C:/msys64/home/stewart/src/TestProject/buildmsys
stewart@PC-1234 MINGW32 ~/src/TestProject/buildmsys
$ cmake --build .
[1/1] Linking CXX executable TestProject.exe
FAILED: TestProject.exe
cmd.exe /C "cd . && C:\msys64\mingw32\bin\c++.exe CMakeFiles/TestProject.dir/main.cpp.obj -o TestProject.exe -Wl,--major-image-version,0,--minor-image-version,0 C:/msys64/mingw32/lib/libboost_log-mt.dll.a C:/msys64/mingw32/lib/libboost_log_setup-mt.dll.a C:/msys64/mingw32/lib/libboost_filesystem-mt.dll.a C:/msys64/mingw32/lib/libboost_thread-mt.dll.a C:/msys64/mingw32/lib/libboost_date_time-mt.dll.a C:/msys64/mingw32/lib/libboost_regex-mt.dll.a C:/msys64/mingw32/lib/libboost_chrono-mt.dll.a C:/msys64/mingw32/lib/libboost_system-mt.dll.a C:/msys64/mingw32/lib/libboost_atomic-mt.dll.a -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
CMakeFiles/TestProject.dir/main.cpp.obj:main.cpp:(.text+0x151): undefined reference to `_imp___ZN5boost3log9v2_mt_nt64core3getEv'
CMakeFiles/TestProject.dir/main.cpp.obj:main.cpp:(.text+0x2b5): undefined reference to `_imp___ZN5boost3log9v2_mt_nt64core10set_filterERKNS1_6filterE'
CMakeFiles/TestProject.dir/main.cpp.obj:main.cpp:(.text+0x35a): undefined reference to `_imp___ZN5boost3log9v2_mt_nt64core3getEv'
CMakeFiles/TestProject.dir/main.cpp.obj:main.cpp:(.text+0x4e2): undefined reference to `_imp___ZN5boost3log9v2_mt_nt64core10set_filterERKNS1_6filterE'
CMakeFiles/TestProject.dir/main.cpp.obj:main.cpp:(.text+0x53c): undefined reference to `_imp___ZN5boost3log9v2_mt_nt67trivial6logger3getEv'
CMakeFiles/TestProject.dir/main.cpp.obj:main.cpp:(.text+0x5a2): undefined reference to `_imp___ZN5boost3log9v2_mt_nt67trivial6logger3getEv'
CMakeFiles/TestProject.dir/main.cpp.obj:main.cpp:(.text$_ZN5boost3log9v2_mt_nt614attribute_nameC1EPKc[__ZN5boost3log9v2_mt_nt614attribute_nameC1EPKc]+0x10): undefined reference to `_imp___ZN5boost3log9v2_mt_nt614attribute_name18get_id_from_stringEPKc'
CMakeFiles/TestProject.dir/main.cpp.obj:main.cpp:(.text$_ZNK5boost3log9v2_mt_nt615value_extractorINS1_7trivial14severity_levelENS1_16fallback_to_noneENS3_3tag8severityEEclERKNS1_14attribute_nameERKNS1_19attribute_value_setE[__ZNK5boost3log9v2_mt_nt615value_extractorINS1_7trivial14severity_levelENS1_16fallback_to_noneENS3_3tag8severityEEclERKNS1_14attribute_nameERKNS1_19attribute_value_setE]+0x19): undefined reference to `_imp___ZNK5boost3log9v2_mt_nt619attribute_value_set4findENS1_14attribute_nameE'
CMakeFiles/TestProject.dir/main.cpp.obj:main.cpp:(.text$_ZNK5boost3log9v2_mt_nt615value_extractorINS1_7trivial14severity_levelENS1_16fallback_to_noneENS3_3tag8severityEEclERKNS1_14attribute_nameERKNS1_19attribute_value_setE[__ZNK5boost3log9v2_mt_nt615value_extractorINS1_7trivial14severity_levelENS1_16fallback_to_noneENS3_3tag8severityEEclERKNS1_14attribute_nameERKNS1_19attribute_value_setE]+0x2e): undefined reference to `_imp___ZNK5boost3log9v2_mt_nt619attribute_value_set3endEv'
CMakeFiles/TestProject.dir/main.cpp.obj:main.cpp:(.text$_ZNK5boost3log9v2_mt_nt615value_extractorINS1_7trivial14severity_levelENS1_16fallback_to_noneENS3_3tag8severityEEclERKNS1_14attribute_nameERKNS1_19attribute_value_setE[__ZNK5boost3log9v2_mt_nt615value_extractorINS1_7trivial14severity_levelENS1_16fallback_to_noneENS3_3tag8severityEEclERKNS1_14attribute_nameERKNS1_19attribute_value_setE]+0xe0): undefined reference to `_imp___ZN5boost3log9v2_mt_nt63aux26attach_attribute_name_infoERNS_9exceptionERKNS1_14attribute_nameE'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
What's wrong with my setup?
Note: I've already checked (and tried) these links in case my question was a duplicate:
Mingw32 Boost Log Link Errors: InterlockedCompareExchange (migration issue)
boost log link error 2019 (BOOST_LOG_DYN_LINK issue)
If I look at those solutions, the unicode one is the only one I haven't gotten to work. I've added add_definitions("-Zc:wchar_t")
to my Cmake file, but I get an unrecognized command line option error from c++.exe (since that flag is VS-specific).
Upvotes: 0
Views: 746
Reputation: 10614
The problem is likely caused by mismatch of the target Windows version between your code and Boost.Log. See this answer:
Problems Linking boost log 1_60 with MinGw on Windows 7
Most likely, your project defines _WIN32_WINNT
somewhere to a value of 0x0600
or higher.
Boost defaults to Windows XP when compiled by MinGW because Windows SDK provided by MinGW is too incomplete.
Upvotes: 1