本文介绍了\ mingw-w64 \ ... \ ld.exe:找不到-lboost_filesystem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在"Windows 7 64bit"命令提示符下使用mingw编译简单的c ++程序.我得到的错误是:

I'm trying to compile simple c++ program with mingw on "windows 7 64bit" command prompt. Error I get is:

>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

也许有用的系统变量信息:

Maybe useful system variable information:

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的内容是:

and a content of boost/lib is:

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

并获得相同的输出.

在我看来,这似乎是一个链接器问题.但是,我没有经验.难道这是库文件编译错误的产物?

To me it looks like a linker problem. But, I'm not experienced. Could this be a product of badly compiled library files?

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

What options should I use when compiling c++ on Windows? Where did I go wrong?

推荐答案

我相信您的问题是由 boost 库文件的复杂命名方案引起的,
请参见 Windows入门:库命名.

I believe that your issue is caused by the complicated naming scheme of boost library files,
see Boost Getting Started on Windows: library naming.

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

In short, boost appends characters to library file names to specify (amongst other things):

  • 编译器版本: -mgw81
  • 多线程: -mt
  • 机器体系结构和地址模型: -x64
  • 和增强版本: -1_70 .

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

Therefore, boost_filesystem becomes: boost_filesystem-mgw81-mt-x64-1_70 and boost_system becomes: boost_system-mgw81-mt-x64-1_70, so try:

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在使用MinGW进行构建时未找到Boost库Windows .

Note: build systems like cmake simplify these issues, but they can introduce new ones, see: cmake FindBoost not finding Boost libraries when building with MinGW on Windows.

这篇关于\ mingw-w64 \ ... \ ld.exe:找不到-lboost_filesystem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 20:50