我有這個cmake的文件:升壓日誌鏈接錯誤(CMake的MINGW32)
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
如果我建立它使用Visual Studio作爲從Visual-Studio的開發者控制檯我產生,我可以建立就好了。但是在我的MinGW32環境中,我收到鏈接器錯誤。我可以確認boost是安裝在我的mingw32環境中的,並且對於其他項目(使用其他boost組件)的工作良好。
[email protected] 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
我構建具有:
$ mkdir buildmsys && cd buildmsys
$ cmake .. -GNinja
$ cmake --build .
這裏是輸出
[email protected] 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
[email protected] 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.
這有什麼錯我的設置?
注:我已經檢查(並試圖)的情況下,這些鏈接我的問題是重複的:
Mingw32 Boost Log Link Errors: InterlockedCompareExchange(移民問題)
boost log link error 2019(BOOST_LOG_DYN_LINK問題)
- Boost-log linker error(Unicode issue)
- link error with boost log(Unicode issue)
- Visual Studio 2013 Boost-log v1_61_0 linking errors(升壓安裝問題)
如果我把這些解決方案,使用Unicode是唯一一個我沒有得到工作。我已經將add_definitions("-Zc:wchar_t")
添加到我的Cmake文件中,但是我從C++。exe中得到了無法識別的命令行選項錯誤(因爲該標誌是VS特定的)。
'我可以證實boost是安裝在我的mingw32環境中,並且對其他項目運行良好。 - 你可以爲其他項目(使用Boost)和**比較**的編譯行與由CMake的? – Tsyvarev