简体   繁体   English

无法使用MSVC链接到Boost库:无法打开文件* .lib

[英]Cannot link to Boost library with MSVC: Cannot open file *.lib

I'm using CLion and CMake to link with Boost and as toolchain I chose the MSVC compiler: 我使用CLionCMakeBoost链接,并且作为工具链,我选择了MSVC编译器:

My architecture is configured as amd64 since I'm running a 64-bit system (the default of x86 only tries to find the 32-bit versions of Boost which I don't want). 由于我运行的是64位系统,因此我的体系结构配置为amd64x86的默认值仅尝试查找我不想要的Boost的32位版本)。

Furthermore I compiled the 64-bit libraries using this guide. 此外,我使用指南编译了64位库。 I setup my CMake file respectively: 我分别设置了我的CMake文件:

set(BOOST_ROOT "C:/local/boost_1_69_0_b1_rc3")
set(BOOST_LIBRARYDIR "C:/local/boost_1_69_0_b1_rc3/stage/x64/lib")
set(BOOST_INCLUDEDIR "C:/local/boost_1_69_0_b1_rc3/boost")

My main.cpp compiles just fine but I'm getting a linker error: 我的main.cpp编译正常,但出现链接器错误:

====================[ 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 --
[ 50%] Linking CXX executable BoostTesting.exe
LINK Pass 1: command "C:\PROGRA~2\MICROS~3\2017\ENTERP~1\VC\Tools\MSVC\1415~1.267\bin\Hostx64\x64\link.exe /nologo @CMakeFiles\BoostTesting.dir\objects1.rsp /out:BoostTesting.exe /implib:BoostTesting.lib /pdb:D:\Cpp\BoostTesting\cmake-build-debug\BoostTesting.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console C:\local\boost_1_69_0_b1_rc3\stage\x64\lib\libboost_filesystem-vc141-mt-gd-x64-1_69.lib C:\local\boost_1_69_0_b1_rc3\stage\x64\lib\libboost_system-vc141-mt-x64-1_69.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\BoostTesting.dir/intermediate.manifest CMakeFiles\BoostTesting.dir/manifest.res" failed (exit code 1104) with the following output:
LINK : fatal error LNK1104: cannot open file 'libboost_iostreams-vc141-mt-gd-x64-1_69.lib'
NMAKE : fatal error U1077: 'C:\Users\User\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\183.4284.104\bin\cmake\win\bin\cmake.exe' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.15.26726\bin\HostX64\x64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.15.26726\bin\HostX64\x64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.15.26726\bin\HostX64\x64\nmake.exe"' : return code '0x2'
Stop.

When using x86_amd64 as architecture it also fails to link. 当使用x86_amd64作为体系结构时,它也无法链接。 The other architectures don't make sense for my PC: 其他架构对我的PC没有意义:

Using the pre-compiled binaries from here also fails to link. 从此处使用预编译的二进制文件也无法链接。 How to fix this linking problem? 如何解决此链接问题?

Just setting BOOST_ROOT in CMakeLists.txt 只需在CMakeLists.txt设置BOOST_ROOT

set(BOOST_ROOT "C:/local/boost_1_69_0_b1_rc3")

and using amd64 as the architecture surprisingly did the trick now. 现在使用amd64作为架构令人惊讶。 Using MSVC with CMake is better supported with Visual Studio (quite obviously) and linking to Boost was no issue anymore. Visual Studio更好地支持了将MSVCCMake一起使用(很明显),并且链接到Boost不再是问题。 Now the build also works from CLion but Visual Studio should be preferred until CLion maybe gets better MSVC integration. 现在,该构建也可以在CLion但是应该首选Visual Studio直到CLion可能获得更好的MSVC集成为止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 链接:致命错误LNK1104:无法打开文件'boost_program_options.lib' - LINK: fatal error LNK1104: cannot open file 'boost_program_options.lib' c ++ boost库无法打开文件 - c++ boost library cannot open file Boost : 致命错误 LNK1104: 无法打开文件 (lib) - Boost : fatal error LNK1104: cannot open file (lib) LNK1104 无法打开文件'boost_regex.lib' - LNK1104 cannot open file 'boost_regex.lib' 链接:致命错误 LNK1104:无法打开文件 'boost_date_time-vc141-mt-1_65_1.lib' - LINK : fatal error LNK1104: cannot open file 'boost_date_time-vc141-mt-1_65_1.lib' Qt 5.5.1 MSVC 2013,32位-LNK1181:无法打开输入文件'NIDAQmx.lib' - Qt 5.5.1 MSVC 2013, 32 bit - LNK1181: cannot open input file 'NIDAQmx.lib' 无法将Boost库链接到共享库 - Cannot link boost library to shared library 无法使用Boost库中的read_ini函数打开ini文件 - Cannot open ini file with read_ini function in boost library “LNK1104:无法打开文件 'mclmcrrtd.lib'”在 Qt Creator 中使用 MSVC 编译 Matlab 代码时出错 - "LNK1104: cannot open file 'mclmcrrtd.lib'" Error When Compiling Matlab Code With MSVC in Qt Creator VS12 Buiding Boost Library致命错误LNK1104:无法打开文件'libboost_system-vc110-mt-gd-1_58.lib' - VS12 Buiding Boost Library fatal error LNK1104: cannot open file 'libboost_system-vc110-mt-gd-1_58.lib'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM