-2

I am trying to switch to Windows environment from Linux, but find it a very hard path.

This time I wanted to test if I can work with boost library.

I had problems with compiling boost on windows, so I downloaded precompiled version. I unpacked everything and tested positively that I can compile the header-only librariers.

Then I copied some simple boost::asio example. I set up everything in Eclipse. Compilation went fine, but during linking I got 'undefined reference' problem to 'boost::system' internal stuff.

C:/Users/jacek/cpp/boost_1_62_0/boost/system/error_code.hpp:221: undefined reference to `boost::system::generic_category()'
C:/Users/jacek/cpp/boost_1_62_0/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()'
C:/Users/jacek/cpp/boost_1_62_0/boost/system/error_code.hpp:223: undefined reference to `boost::system::system_category()'

So I added '-lboost_system', as well as the path to the libraries directory, to my linking options. But this did not help.

g++ "-LC:\\Users\\jacek\\cpp\\boost_1_62_0\\lib64-msvc-14.0" -o TestAsio.exe "src\\Main.o" -lboost_system 

I checked the libraries directory and found there is a bunch of files containing 'boost_system' in the name. They are:

  • libboost_system-vc140-mt-1_62.lib
  • libboost_system-vc140-mt-gd-1_62.lib
  • libboost_system-vc140-mt-s-1_62.lib
  • libboost_system-vc140-mt-sgd-1_62.lib
  • libboost_system-vc140-s-1_62.lib
  • libboost_system-vc140-sgd-1_62.lib

I did not know which I should use. I tried adding 'libboost_system-vc140-mt-1_62' to the linking options, I tried all other files, I tried renaming the files to the linux pattern 'libboost_system.a', but nothing worked.

g++ "-LC:\\Users\\jacek\\cpp\\boost_1_62_0\\lib64-msvc-14.0" -o TestAsio.exe "src\\Main.o" -llibboost_system-vc140-mt-1_62 -llibboost_system-vc140-mt-gd-1_62 -llibboost_system-vc140-mt-s-1_62 -llibboost_system-vc140-mt-sgd-1_62 -llibboost_system-vc140-s-1_62 -llibboost_system-vc140-sgd-1_62 

What am I doing wrong here? Please help... YotKay

YotKay
  • 1,127
  • 1
  • 9
  • 25
  • 1
    "-LC:\\ looks strange, -L "C:\\ ? – willll Dec 23 '16 at 19:55
  • I think I found myself a solution here: http://boost.org/more/getting_started/windows.html – YotKay Dec 23 '16 at 20:02
  • 2
    The point is that the precompiled binaries were compiled with Visual Studio and they are NOT COMPATIBLE with G++. Shit! – YotKay Dec 23 '16 at 20:02
  • Binaries are also not compatible with any other version of Visual Studio than the one the compiled them. That is why there are released binaries for several different compilers. – drescherjm Dec 23 '16 at 20:50

1 Answers1

1

I solved it myself with the help of a comment from this post: boost asio example compilation error

It looks like the precompiled version of Boost is created with Visual Studion and is NOT COMPATIBLE with G++. I if I decided to install MinGW then I cannot use the precompiled version of boost, but must compile it myself using g++.

I did that. Now I have libraries compiled with G++.

I specify the path to the boost system library like that: c:\Users\jacek\cpp\boost_1_62_0\libraries\boost\bin.v2\libs\system\build\gcc-mingw-6.2.0\debug\link-static\

and add this option: -lboost_system-mgw62-d-1_62

Now the problem with boost::system disappears. However, another one pops up with boost asio, but luckily the answer is here: MinGW linker error: winsock

The example works fine now on my Windows 10 laptop.

#include <boost/asio/io_service.hpp>
#include <boost/asio/steady_timer.hpp>
#include <chrono>
#include <iostream>

using namespace boost::asio;

int main()
{
  io_service ioservice;

  steady_timer timer{ioservice, std::chrono::seconds{3}};
  timer.async_wait([](const boost::system::error_code &ec)
    { std::cout << "3 sec\n"; });

  ioservice.run();
}
Community
  • 1
  • 1
YotKay
  • 1,127
  • 1
  • 9
  • 25