TiManGames / AmnesiaTheDarkDescent

GNU General Public License v3.0
30 stars 8 forks source link

MinGW+CMake crosscompilation for Windows #18

Open jkulawik opened 1 month ago

jkulawik commented 1 month ago

This is needed because if someone on Windows compiles the editors, they can release them without the Linux builds (since there's very few users for that). Meanwhile, a Linux developer can't do much with their builds because most people use Windows.

Hopefully helpful link: https://cmake.org/cmake/help/book/mastering-cmake/chapter/Cross%20Compiling%20With%20CMake.html

jkulawik commented 3 weeks ago

Resolved some issues and got the toolchain to work, but at the moment progress is stopped by a redaclaration within FBX SDK headers and the libraries they import (math stuff that's taken from mingw, in this case; so it might not act the same on native windows).

This does not occur during Linux builds, so it is possible that this is caused by some mistake with the include lists.

jkulawik commented 2 weeks ago

The supplied .lib files seem to have been compiled with MSVC (i.e. Visual Studio), which seems to be incompatible with MinGW.

https://stackoverflow.com/questions/2472924/linking-to-msvc-dll-from-mingw

You can't do this. They have exported C++ classes from their dll, rather than C-functions. The difference is, c++ functions are always exported with names in a mangled form that is specific to a particular version of the compiler.

Otherwise you will need to use MSVC to write a shim dll, that will import all the classes, and re-export them via c functions that return interfaces.

An example of writing a shim can be found here. However, given the number of libs which potentially have this issue, this fix is not very viable.

Another solution would be to do one of the following:

On the other hand: https://stackoverflow.com/questions/2529770/how-to-use-libraries-compiled-with-mingw-in-msvc

Even though GNU g++ can link MSVC C++ libraries now, and can produce MSVC++ compatible libraries/DLLs, this does not mean that they will be able to work at run-time due to the dynamic nature of C++.

This means that it should be possible, but the dlls would be useless, so we probably need the other fix anyway.

jkulawik commented 2 weeks ago

Worth noting: https://www.mingw-w64.org/

Tools gendef: generate Visual Studio .def files from .dll files.

Might be helpful, but probably won't.

jkulawik commented 1 week ago

Got the MinGW builds to compile, but they're broken - probably because non-MinGW libraries are still being used.