Author Topic: Compiling Levels on Linux  (Read 2472 times)

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Compiling Levels on Linux
« on: November 23, 2017, 07:17:22 AM »
I was able to successfully compile an Outpost 2 mission on Linux, and tested it in game under Wine. Here's a bit of info on the process.

I used the MinGW compiler to cross compile from Linux for Windows. Normally MinGW would be used from Windows to compile for Windows, but it can also be run from Linux as a cross compiler for Windows.

From the Wikipedia article on MinGW:
Quote
It includes a port of the GNU Compiler Collection (GCC), GNU Binutils for Windows (assembler, linker, archive manager), a set of freely distributable Windows specific header files and static import libraries which enable the use of the Windows API, a Windows native build of the GNU Project's GNU Debugger, and miscellaneous utilities.



Installation on Ubuntu:
Code: [Select]
sudo apt install g++-mingw-w64
Note: The "g++-" prefix limits installation to only the C/C++ compiler. This saves a considerable amount of space. There are other languages supported too (such as Objective-C/C++, Fortran, Ada).

I was then able to compile the level DLL from the LevelsAndMods/trunk/LevelTemplates/Blank project in the SVN repo:
Code: [Select]
i686-w64-mingw32-g++-win32 -std=c++11 -I../../API/ -shared -o cLevel.DLL *.cpp
This compiled successfully (though with a few warnings). I copied the DLL to the game folder, and it loaded up with no problems.

As for the warnings, the compiler was being overly cautious about the level export data being defined and exported in the same line. An easy fix to the SDK eliminates the warning. Just update the SDK header macro to declare the exports first, and then define them afterwards. No changes needed to the level's code.

Offline Arklon

  • Administrator
  • Hero Member
  • *****
  • Posts: 1269
Re: Compiling Levels on Linux
« Reply #1 on: November 23, 2017, 09:19:40 PM »
Have you tried Clang? I would think that'd also work.

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Re: Compiling Levels on Linux
« Reply #2 on: November 24, 2017, 01:47:32 AM »
Hmm, interesting point. Clang does do cross compiling. Though it doesn't come pre-packaged with windows header files. A naive attempt at compiling with Clang complains about a missing windows.h.

I did a bit of reading, and it seems it's possible if you can get the headers and libs from somewhere else, such as the MinGW project, or from a Visual Studio install.

Have you got something like this working?