3

I have a c++ codebase that I need to build both windows and unix versions of. It is important that the windows executable work without cygwin or similar installed. Oh, and I'm trying to achieve this from ubuntu.

I've been trying to figure out how to make boost-build take care of it, but have so far come up short.. For simplicity assume this project structure:

root/
|- src/
|  |- core/
|  |  |- number.cpp
|  |  |- number.hpp
|  |- main.cpp
|- jamroot

In an attempt to make boost-build produce windows binaries as a first step, I create a user-config.jam file in my home directory containing the following:

using gcc : 4.4 : i586-mingw32msvc-g++ : <rc>i586-mingw32msvc-windres <archiver>i586-mingw32msvc-ar ;

My jamroot file looks like this:

exe hello :
    [ glob-tree *.cpp ]
    : : <target-os>windows
;

But when I run bjam I get a unix executable (no extension) but not a windows executable. Renaming the application with a .exe extension and running on windows does not work. I tried various options for bjam, like bjam --toolset=gcc --target-os=windows, bjam --toolset=gcc-mingw --target-os=windows etc. but noting seems to work..

For the record, mingw is properly installed and working.. Calling the compiler manually produces correct output files.

Any ideas?

Also, how do I get bjam to build a version for each toolset listed in my user-config.jam file?

Bonus question: Eventually, I need to link against one boost library and one custom prebuilt library. How would I go about specifying different libraries for the different target systems?

UPDATE I downloaded the script from http://mingw-cross-env.nongnu.org/ which allowed me to compile a mingw as well as boost libraries in one go, so that problem is taken care of.. I found a way to make bjam call the mingw compiler (I am at a different computer so I cannot provide the solution at this time).. The other questions are still not resolved.

2
  • Have you installed mingw in your linux box? Also refer here: mingw.org/wiki/LinuxCrossMinGW Commented Apr 22, 2011 at 17:49
  • Yes, as written in the question, mingw is installed and working.. Calling the mingw compiler manually correctly produces windows executables.. Commented Apr 22, 2011 at 17:55

3 Answers 3

1

Unfortunately I don't think this can be done (I've failed many times) and I think the reason is because mingw is not suppported for compiling Boost. The only way people seem to have accomplished this is to maintain a separate build environment under win32 using MS Visual Studio.

From your question it's unclear if you're using bjam to build your application, or if you're just trying to build Windows versions of the Boost libraries (.lib or .dll files) to link with your application later. In my attempts I have tried to do this the 'usual' way, in that Windows versions of the Boost libraries are compiled, then the app is compiled separately with mingw32 and linked with Boost.

Unfortunately my stumbling block so far is that I can only get two outcomes - either the build fails when compiling Boost into Win32 dynamic libraries (.dll), or win32 static libraries are successfully built, but then libtool refuses to link them in with the app.

Have a look at the PKGBUILD file that Arch Linux uses to compile mingw32-boost as you might get some hints from how they do it. It seems that bjam threadapi=win32 target-os=windows is enough. Don't forget to set your prefix correctly though, so you don't overwrite your native libraries with win32 versions!

Sign up to request clarification or add additional context in comments.

2 Comments

I am trying to compile the boost libraries as well as my own application which depends on boost::program_options.. Unfortunately, my application depends on another library which cannot be built using MSVC which means I am forced to use mingw..
@Morten Jacobsen: You can still compile your own program with mingw, but AFAIK you must use MSVC to compile the Boost libraries (if you want .dll files.) You can use mingw to build static Boost libs, but then I'm not sure how you're supposed to link an app with them. I'm not familiar with using bjam to compile custom apps though, as I've been using the GNU autotools for that.
0

On my ubuntu box, it is as simple as

sudo apt-get install mingw

and then build

export CC=i586-mingw32msvc-gcc
make 

Profit!

1 Comment

mmm not very helpful, alas there is no delete button for some reason. Maybe later
0

I know that it's old but since I stumbled upon this thread while searching for the answer I'll leave the answer here.

So I needed to compile the Boost::Asio project for Windows using mingw on Ubuntu.

Firstly I built a Linux version which worked well. Then I tried to include a toolchain file with instructions for the windows I was targeting. After I finished my setup I got this kind of error:

I had to download Boost lib for Windows and set it up in my CMakeLists.txt After that I got a new error:

I had to add another line to CMakeLists.txt and exe. cpp, right after add_executable I had to specify "target_link_libraries(executable_name ws2_32)" and to exe. cpp "#pragma comment(lib, "Ws2_32.lib")"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.