0

I'm trying to build the following code:

Content of "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.

P.s. Space after "-L" and "-I" is allowed. And I've tried to link different libs. For shared I also used #define BOOST_ALL_DYN_LINK just in case.

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
vamirio-chan
  • 339
  • 1
  • 13
  • 2
    Doesn't `vc142` in `boost_filesystem-vc142-mt-gd-x32` mean this library was built for MSVC? If so, it's not compatible with MinGW. You need a version built for MinGW. – HolyBlackCat Mar 10 '20 at 13:51
  • You need to build boost with the compiler you are using. Visual Studio binaries are no use. – drescherjm Mar 10 '20 at 13:52
  • I'd suggest installing MSYS2. You'll get a prebuilt Boost and a fresh version of GCC as a bonus. – HolyBlackCat Mar 10 '20 at 13:58
  • Those are Visual Studio 2019 libraries (free for most users!). You will need to get or build your own, building Boost from source is not that hard, there are [step by step instructions on the site](https://www.boost.org/doc/libs/1_72_0/more/getting_started/windows.html), although Boost doesn't appear to officially support MSYS. – Fire Lancer Mar 10 '20 at 13:58
  • Thx, I chose toolset=gcc and built libs I needed. It works! – vamirio-chan Mar 10 '20 at 14:07

1 Answers1

0

Visual Studio binaries for boost are incompatible with MinGW. You will need boost binaries that were produced with your toolchain. While many c libraries can use binaries produced by other c compilers c++ libraries are generally not compatible.

The following question explains the difficulties of ABI incompatibility in c++: Easy way to guarantee binary compatibility for C++ library, C linkage?

drescherjm
  • 10,365
  • 5
  • 44
  • 64