Question

I'm trying to cross-compile on Linux for Win64 using MinGW-w64. Here's my code

#include <cstdlib>
#include <iostream>

#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>

int main(int argc, char** argv)
{
    if (argc > 1)
        std::cout << std::atoi(argv[1]) << std::endl;

    std::cout << boost::uuids::random_generator()() << std::endl;

    return 0;
}

A simple compile fails with the error

$ x86_64-w64-mingw32-c++ hello.cpp
hello.cpp:4:31: fatal error: boost/uuid/uuid.hpp: No such file or directory
 #include <boost/uuid/uuid.hpp>
                               ^

Boost is installed in /usr/include which apparently the MinGW compiler doesn't search. If I add that path, then...

$ x86_64-w64-mingw32-c++ -I/usr/include hello.cpp
In file included from /usr/include/stdlib.h:314:0,
             from /usr/x86_64-w64-mingw32/include/c++/4.9.1/cstdlib:72,
             from hello.cpp:1:
/usr/include/sys/types.h:109:19: error: conflicting declaration ‘typedef __ssize_t ssize_t’
 typedef __ssize_t ssize_t;
                   ^

MinGW's cstdlib is including /usr/include/stdlib.h instead of /usr/x86_64-w64-mingw32/include/stdlib.h! How do I solve this? I need the -I in order to include Boost, but then MinGW includes other headers incorrectly.

Was it helpful?

Solution

You cannot use boost headers from /usr/include to cross-compile windows binaries.

You should also cross-compile boost.

See this guide for details about how to cross-compile boost on linux (it's for vle, but the first part is about boost):

http://www.vle-project.org/wiki/Cross_compilation_Win32

Update: Given that the guide is a little bit old, makes sense to link to boost documentation:

http://www.boost.org/boost-build2/doc/html/bbv2/tasks/crosscompile.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top