0

Hi I'm trying to build a demo example from boost C++ And I get the following errors when building

g++.exe -Wall -fexceptions -std=c++11 -g -IC:\boost -c C:\api\api\main.cpp -o obj\Debug\main.o g++.exe -LC:\boost\stage\lib -o bin\Debug\api.exe obj\Debug\main.o C:\boost\stage\lib\libboost_system-vc142-mt-gd-x64-1_75.lib C:\boost\stage\lib\libboost_filesystem-vc142-mt-gd-x64-1_75.lib obj\Debug\main.o: In function main': C:/api/api/main.cpp:31: undefined reference to boost::filesystem::path::make_preferred()' C:/api/api/main.cpp:34: undefined reference to boost::filesystem::path::begin() const' C:/api/api/main.cpp:34: undefined reference to boost::filesystem::path::end() const'

Judging by what I found on the internet: this,this, and this I need to rebuild boost with C++11 support and build my project by explicitly specifying the standard.

I built boost again by running:

C:\boost>b2.exe toolset=gcc cxxflags="-std=c++11"

When building my project, I will add a key

-std=c++11

But I get all the same errors, and the tips from the Internet do not work for me, tell me how to overcome this problem?

stas stas
  • 95
  • 10

1 Answers1

1
  1. You are trying to link with a boost library built with the microsoft compiler. That's what the "vc142" in the name of the library file means. That cannot work, you must build boost with the same compiler you are planning on using for building your application.

  2. Libraries should be linked using the '-l' flag, either in this form:

-lboost_system-<compiler+version>-mt-gd-x64-1_75

Omitting path (which is specified with the -L flag), the 'lib' prefix in the file name and the file extension.

Or with '-l:', as in:

-l:C:\boost\stage\lib\libboost_system-<compiler+version>-mt-gd-x64-1_75.so

Usually, boost makes linking to the right library transparent, and you shouldn't have to specify the name of the boost library you are linking to. You'll still need to specify, with the -L flag, where the boost libraries are located.

If you still want to explicitely state which library to link with, the 'mt-gd', indicates your are linking your app with the multithreaed debug runtime library. These options have to match the compiler and linker flags you are using to build your application.

See the boost documentation for details on specifying your toolset for building the boost libraries. https://www.boost.org/doc/libs/1_75_0/more/getting_started/windows.html

Michaël Roy
  • 6,338
  • 1
  • 15
  • 19