How to get Boost::asio working with MinGW

Started by
2 comments, last by SolDirix 9 years, 1 month ago

I seem to be having trouble getting Boost::asio to work with MinGW with Eclipse.

I am using Boost version 1.50.

I have read around and am suprised very few people had this problem. I get this error when trying to use the Boost::asio Library:

"swprintf was not declared in this scope"

I got this error when I tried to use:

#define WIN32_WINNT 0x0501
#define WINVER 0x0501

in order to get around the UnregisteredWaitEx has not been declared error. Which seems unfortunate, because this makes the windows library for Windows XP the library to use. What if I want to use Windows 8 features?

Isn't there another way? I can get other Boost libraries to work, including Thread and XML.

I hear that often times these problems are due to ordering, but i've been switching things around and I still can't get rid of the error.

This is the order I am including:

#include <boost/bind.hpp>
#include <boost/asio.hpp>
#include <boost/thread/thread.hpp>

#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <winsock2.h>
#include <glew.h>
#include <glfw3.h>

The libraries are in the same order.

How do you get Boost::asio to work? Preferably without having to downgrade to WindowsXP windows.h.

View my game dev blog here!

Advertisement

Boost 1.57 is the latest, so you might want to upgrade.

I don't use the ASIO library myself, but in the revision history for ASIO, it says they fixed the error you are encountering in Boost 1.53.

Asio 1.8.3 / Boost 1.53 - "Changed to use _snwprintf to address a compile error due to the changed swprintf signature in recent versions of MinGW (#7373)"

If for some reason you are unable to upgrade to the latest Boost version, you could do a diff of the two ASIO versions (the latest and the outdated one you are currently using) and patch in the fixes yourself. But if you can, it'd probably be better just to upgrade the entire Boost library collection to the latest.

There are also MinGW distributions which already include pre-built Boost binaries:

- http://nuwen.net/mingw.html

- https://msys2.github.io/

Perhaps it would be easier to use one of these?

Alternatively, in case you only want ASIO, there's also a standalone (non-Boost) version only requiring a C++11 compiler:

http://think-async.com/

Boost 1.57 is the latest, so you might want to upgrade.

Thanks :3. I got it working, but I still had to add #define WIN32_WINNT 0x0501 #define WINVER 0x0501. It just seems 'wrong' using a Windows XP version of the windows library in order for it to work. I wouldn't be able to use Windows 8 features, but then again I might need vs for that. Surely there has to be a way around this.

View my game dev blog here!

This topic is closed to new replies.

Advertisement