[英]Cant link boost library with g++ Windows
I'm trying to build the following code:我正在尝试构建以下代码:
Content of "Source.cpp" “Source.cpp”的内容
#include <boost/filesystem.hpp>
using namespace boost::filesystem;
int main(int argc, char* argv[])
{
path myPath("foo");
if (exists(myPath)) ...
}
The command that I use to compile it is:我用来编译它的命令是:
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
But I get default unresolved symbol errors:但我得到默认的未解决的符号错误:
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
There's no problem when I compile it with Visual Studio though.不过,当我用 Visual Studio 编译它时没有问题。
Ps Space after "-L" and "-I" is allowed. Ps "-L" 和 "-I" 后面的空格是允许的。 And I've tried to link different libs.我试图链接不同的库。 For shared I also used #define BOOST_ALL_DYN_LINK just in case.对于共享,我还使用了 #define BOOST_ALL_DYN_LINK 以防万一。
Shared:共享:
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
Static:静止的:
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
binaries for boost are incompatible with MinGW
.用于 boost 的Visual Studio
二进制文件与MinGW
不兼容。 You will need boost binaries that were produced with your toolchain.您将需要使用工具链生成的 boost 二进制文件。 While many c
libraries can use binaries produced by other c
compilers c++
libraries are generally not compatible.虽然许多c
库可以使用其他c
编译器生成的二进制文件,但c++
库通常不兼容。
The following question explains the difficulties of ABI incompatibility in c++
: Easy way to guarantee binary compatibility for C++ library, C linkage?下面的问题解释了c++
中 ABI 不兼容的困难: 保证 C++ 库的二进制兼容性的简单方法,C 链接?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.