[英]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: 我使用CLion
和CMake
与Boost
链接,并且作为工具链,我选择了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位系统,因此我的体系结构配置为amd64
( x86
的默认值仅尝试查找我不想要的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
更好地支持了将MSVC
与CMake
一起使用(很明显),并且链接到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.