Cross-compiling for windows from Linux


#1

Hello again. I’ve been using chaiscript in my project for a while, and I’m loving it. But now I’m trying to update my windows build, which I do through MinGW on ubuntu 14.04.

This is the very simple cmake toolchain file I’ve been using, which works for both my project and SFML:

SET(CMAKE_SYSTEM_NAME Windows)

SET(CMAKE_C_COMPILER i686-w64-mingw32-gcc)
SET(CMAKE_CXX_COMPILER i686-w64-mingw32-g++)
SET(CMAKE_RC_COMPILER i686-w64-mingw32-windres)

SET(CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32 )

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

But, upon running cmake with this toolchain, I get:

-- The C compiler identification is GNU 4.8.2
-- The CXX compiler identification is GNU 4.8.2
-- Check for working C compiler: /usr/bin/i686-w64-mingw32-gcc
-- Check for working C compiler: /usr/bin/i686-w64-mingw32-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/i686-w64-mingw32-g++
-- Check for working CXX compiler: /usr/bin/i686-w64-mingw32-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Checking C++11 support for "auto" (N2546)
CMake Error: TRY_RUN() invoked in cross-compiling mode, please set the following cache variables appropriately:
   _RUN_RESULT_VAR (advanced)
For details see /home/jagoly/Projects/ChaiScript-5.6.0/TryRunResults.cmake
-- Checking C++11 support for "auto" (N2546) -- not supported
-- Checking C++11 support for "nullptr" (N2431)
-- Checking C++11 support for "nullptr" (N2431) -- not supported
-- Checking C++11 support for "lambda" (N2927)
-- Checking C++11 support for "lambda" (N2927) -- not supported
-- Checking C++11 support for "static_assert" (N1720)
-- Checking C++11 support for "static_assert" (N1720) -- not supported
-- Checking C++11 support for "rvalue_references" (N2118)
-- Checking C++11 support for "rvalue_references" (N2118) -- not supported
-- Checking C++11 support for "decltype" (N2343)
-- Checking C++11 support for "decltype" (N2343) -- not supported
-- Checking C++11 support for "cstdint"
-- Checking C++11 support for "cstdint" -- not supported
-- Checking C++11 support for "long_long" (N1811)
-- Checking C++11 support for "long_long" (N1811) -- not supported
-- Checking C++11 support for "variadic_templates" (N2555)
-- Checking C++11 support for "variadic_templates" (N2555) -- not supported
-- Checking C++11 support for "constexpr" (N2235)
-- Checking C++11 support for "constexpr" (N2235) -- not supported
-- Checking C++11 support for "sizeof_member" (N2253)
-- Checking C++11 support for "sizeof_member" (N2253) -- not supported
-- Checking C++11 support for "__func__" (N2340)
-- Checking C++11 support for "__func__" (N2340) -- not supported
CMake Error at CMakeLists.txt:114 (message):
  The selected compiler does not support the C++11 feature Variadic
  Templates.


-- Detecting readline support
-- Not Found
add lots of tests...

I know that this mingw version supports all of that stuff, as I’m using most of it. So, what am I missing to get this working? Naively adding -D_RUN_RESULT_VAR=0 removes all of the compaints except the readline and variadic templates, but it still doesn’t work.


Compiled in Std Lib with MinGW
#2

Ok, I got it “working” by changing HAS_CXX11_VARIADIC_TEMPLATES:INTERNAL in CMakeCache to true. Also, I had to install libdl.a from https://github.com/dlfcn-win32/dlfcn-win32/releases to get it to link. And, I had to change #include <Windows.h> to a lowercase W in chaiscript_engine.hpp.

Anyway, it now builds and works well, and my application will run in wine.

Although, there were a LOT of scary looking warnings when running make about things not being thread-safe and using old style casts, that I didn’t get building for linux.

So I guess a bit of a guide on how this should be done properly wouldn’t hurt :slight_smile:


#3

Well, if I’d gotten to your question sooner, I probably would have suggested doing a compiled-in stdlib when cross-compiling, just to avoid random issues like this.

Or, if you are compiling in the stdlib, then you didn’t need to bother with compiling ChaiScript at all - just include the headers.

The non-thread-safety isn’t surprising, I believe that’s disabled when compiling with mingw due to limitations with mingw. The c-style casts is surprising. Can you paste a few examples of where that’s occurring?

Thanks,
Jason


#4

Sure, here’s the output of the first thing make builds.

[  3%] Building CXX object CMakeFiles/arithmetic_conversions_test.dir/unittests/arithmetic_conversions_test.cpp.obj
In file included from /home/jagoly/Projects/ChaiScript-5.6.0/include/chaiscript/dispatchkit/dispatchkit.hpp:26:0,
                 from /home/jagoly/Projects/ChaiScript-5.6.0/include/chaiscript/chaiscript.hpp:795,
                 from /home/jagoly/Projects/ChaiScript-5.6.0/unittests/arithmetic_conversions_test.cpp:3:
/home/jagoly/Projects/ChaiScript-5.6.0/include/chaiscript/dispatchkit/../chaiscript_threading.hpp:16:66: note: #pragma message: ChaiScript is compiling without thread safety.
 #pragma message ("ChaiScript is compiling without thread safety.")
                                                                  ^
In file included from /home/jagoly/Projects/ChaiScript-5.6.0/include/chaiscript/chaiscript.hpp:801:0,
                 from /home/jagoly/Projects/ChaiScript-5.6.0/unittests/arithmetic_conversions_test.cpp:3:
/home/jagoly/Projects/ChaiScript-5.6.0/include/chaiscript/language/chaiscript_engine.hpp: In static member function ‘static std::string chaiscript::detail::Loadable_Module::get_error_message(DWORD)’:
/home/jagoly/Projects/ChaiScript-5.6.0/include/chaiscript/language/chaiscript_engine.hpp:185:26: warning: use of old-style cast [-Wold-style-cast]
             (StringType)&lpMsgBuf,
                          ^
Linking CXX executable arithmetic_conversions_test.exe

Yeah, I guess just compiling chaiscript in would work well enough for windows, as I don’t have to build that constantly. But now that it is working, it seems like it’s just an issue with the Cmake scripts rather than a hard limitation of mingw.