gpt4 book ai didi

c++ -\mingw-w64\...\ld.exe : cannot find -lboost_filesystem

转载 作者:可可西里 更新时间:2023-11-01 10:41:06 26 4
gpt4 key购买 nike

我正在尝试在“Windows 7 64 位”命令提示符下使用 mingw 编译简单的 C++ 程序。我得到的错误是:

>gcc fs.cpp -lboost_filesystem -lboost_system
c:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lboost_filesystem
c:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lboost_system
collect2.exe: error: ld returned 1 exit status

可能有用的系统变量信息:

c:\Boost\lib>echo %path%
C:\Boost\boost-build\bin;C:\ProgramData\Oracle\Java\javapath;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\Skype\Phone\;c:\Program Files\mingw-w64\x86_64-8.1.0-win32-seh-rt_v6-rev0\mingw64\bin\;c:\Boost\lib\

c:\Boost\lib>echo %library_path%
c:\Boost\lib

c:\Boost\lib>echo %cplus_include_path%
c:\Boost\include\

boost/lib 的内容是:

c:\Boost\lib>dir
Volume in drive C is Acer
Volume Serial Number is 62C5-4B7E

Directory of c:\Boost\lib

13.06.2019. 00:31 <DIR> .
13.06.2019. 00:31 <DIR> ..
13.06.2019. 00:28 5.608.426 libboost_filesystem-mgw81-mt-d-x32-1_70
13.06.2019. 00:28 6.553.512 libboost_filesystem-mgw81-mt-d-x64-1_70
13.06.2019. 00:28 3.713.979 libboost_filesystem-mgw81-mt-d-x64-1_70
13.06.2019. 00:28 92.342 libboost_filesystem-mgw81-mt-d-x64-1_70
13.06.2019. 00:28 344.104 libboost_filesystem-mgw81-mt-s-x32-1_70
13.06.2019. 00:28 405.348 libboost_filesystem-mgw81-mt-s-x64-1_70
13.06.2019. 00:28 5.608.426 libboost_filesystem-mgw81-mt-sd-x32-1_7
13.06.2019. 00:28 6.553.512 libboost_filesystem-mgw81-mt-sd-x64-1_7
13.06.2019. 00:28 344.104 libboost_filesystem-mgw81-mt-x32-1_70.a
13.06.2019. 00:28 405.348 libboost_filesystem-mgw81-mt-x64-1_70.a
13.06.2019. 00:28 239.395 libboost_filesystem-mgw81-mt-x64-1_70.d
13.06.2019. 00:28 92.132 libboost_filesystem-mgw81-mt-x64-1_70.d
13.06.2019. 00:28 2.822 libboost_system-mgw81-mt-d-x32-1_70.a
13.06.2019. 00:28 3.118 libboost_system-mgw81-mt-d-x64-1_70.a
13.06.2019. 00:28 49.550 libboost_system-mgw81-mt-d-x64-1_70.dll
13.06.2019. 00:28 1.772 libboost_system-mgw81-mt-d-x64-1_70.dll
13.06.2019. 00:28 730 libboost_system-mgw81-mt-s-x32-1_70.a
13.06.2019. 00:28 924 libboost_system-mgw81-mt-s-x64-1_70.a
13.06.2019. 00:28 2.822 libboost_system-mgw81-mt-sd-x32-1_70.a
13.06.2019. 00:28 3.118 libboost_system-mgw81-mt-sd-x64-1_70.a
13.06.2019. 00:28 730 libboost_system-mgw81-mt-x32-1_70.a
13.06.2019. 00:28 924 libboost_system-mgw81-mt-x64-1_70.a
13.06.2019. 00:28 47.834 libboost_system-mgw81-mt-x64-1_70.dll
13.06.2019. 00:28 1.760 libboost_system-mgw81-mt-x64-1_70.dll.a

我尝试用

手动包含路径
gcc fs.cpp -o fs.exe -Lc:\Boost\lib -lboost_filesystem -lboost_system

或与

gcc fs.cpp -o fs.exe -L c:\Boost\lib -lboost_filesystem -lboost_system

或与

gcc fs.cpp -o fs.exe -L c:\Boost\lib -llibboost_filesystem -llibboost_system

并得到相同的输出。

对我来说,这看起来像是链接器问题。但是,我没有经验。这可能是编译错误的库文件的结果吗?

在 Windows 上编译 c++ 时应该使用哪些选项?我哪里出错了?

最佳答案

我认为您的问题是由boost 库文件的复杂命名方案引起的,
Boost Getting Started on Windows: library naming .

简而言之,boost 将字符附加到库文件名以指定(除其他事项外):

  • 编译器版本:-mgw81,
  • 多线程:-mt,
  • 机器架构和地址模型:-x64
  • 和 boost 版本:-1_70

因此,boost_filesystem 变为:boost_filesystem-mgw81-mt-x64-1_70boost_system 变为:boost_system-mgw81-mt -x64-1_70,所以尝试:

gcc fs.cpp -o fs.exe -Lc:\Boost\lib -lboost_filesystem-mgw81-mt-x64-1_70 -lboost_system-mgw81-mt-x64-1_70

注意:构建类似 cmake 的系统简化这些问题,但它们可以引入新问题,请参阅:cmake FindBoost not finding Boost libraries when building with MinGW on Windows .

关于c++ -\mingw-w64\...\ld.exe : cannot find -lboost_filesystem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56571745/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com