提升日志链接错误(Cmake Mingw32)

时间:2017-07-18 08:32:16

标签: c++ boost cmake mingw mingw32

我有这个cmake文件:

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环境中,我遇到链接器错误。我可以确认在我的mingw32环境中安装了boost,并且适用于其他项目(使用其他boost组件)。

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

我建立:

$ mkdir buildmsys && cd buildmsys
$ cmake .. -GNinja
$ cmake --build .

这是输出

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.

我的设置有什么问题?

注意:我已经检查过(并尝试过)这些链接以防我的问题重复:

如果我查看这些解决方案,unicode one是唯一一个我没有工作的解决方案。我已将add_definitions("-Zc:wchar_t")添加到我的Cmake文件中,但是我从c ++。exe中得到一个无法识别的命令行选项错误(因为该标志是VS特定的)。

1 个答案:

答案 0 :(得分:1)

问题可能是由于代码和Boost.Log之间的目标Windows版本不匹配造成的。看到这个答案:

Problems Linking boost log 1_60 with MinGw on Windows 7

您的项目最有可能将public function method() { ... return view('example')->with(['variables'=>'VARIABLE TEXT']); //example refers to example.blade.php //eg: yourpage refers to yourpage.blade.php //with subdirectories: foo.bar refers to foo/bar.blade.php } 定义为值_WIN32_WINNT或更高。

由MinGW编译时,默认为Windows XP,因为MinGW提供的Windows SDK太不完整。