不能 link 使用 g++ Windows 提升库

Cant link boost library with g++ Windows

我正在尝试构建以下代码:

"Source.cpp"

的内容
#include <boost/filesystem.hpp>
using namespace boost::filesystem;

int main(int argc, char* argv[])
{
   path myPath("foo");

   if (exists(myPath)) ...
}

我编译的命令是:

g++ -Wall -I D:\boost_1_72_0 Source.cpp -o test -L D:\boost_1_72_0\stage\lib -lboost_filesystem-vc142-mt-gd-x32-1_72

但我收到默认的未解析符号错误:

C:\Users\User\AppData\Local\Temp\ccskBqAh.o:Source.cpp:(.text$_ZN5boost10filesystem11path_traits7convertEPKcS3_RNSt7__cxx1112basic_stringIwSt11char_traitsIwESaIwEEE[__ZN5boost10filesystem11path_traits7convertEPKcS3_RNSt7__cxx1112basic_stringIwSt11char_traitsIwESaIwEEE]+0x7): undefined reference to `boost::filesystem::path::codecvt()'
... etc

不过用Visual Studio编译没问题

P.s。 Space 在“-L”和“-I”之后是允许的。我已经尝试 link 不同的库。对于共享,我还使用了#define BOOST_ALL_DYN_LINK 以防万一。

共享:

boost_filesystem-vc142-mt-gd-x32-1_72
boost_filesystem-vc142-mt-gd-x64-1_72
boost_filesystem-vc142-mt-x32-1_72
boost_filesystem-vc142-mt-x64-1_72

静态:

libboost_filesystem-vc142-mt-gd-x32-1_72
libboost_filesystem-vc142-mt-gd-x64-1_72
libboost_filesystem-vc142-mt-sgd-x32-1_72
libboost_filesystem-vc142-mt-sgd-x64-1_72
libboost_filesystem-vc142-mt-s-x32-1_72
libboost_filesystem-vc142-mt-s-x64-1_72
libboost_filesystem-vc142-mt-x64-1_72

Visual Studio boost 二进制文件与 MinGW 不兼容。您将需要使用您的工具链生成的 boost 二进制文件。虽然许多 c 库可以使用其他 c 编译器生成的二进制文件 c++ 库通常不兼容。

下面的问题解释了 c++ 中 ABI 不兼容的困难: