Compiling windows cpp from linux using minGW, Its Possible!

You can’t do that, that’s not how compilers work. Compilers are designed to build source for the platform you’re currently using, not for a platform you’re not using. It’s the same reason you can’t just build a Mac application using openfl build mac on Windows.

It will look like it works because hxcpp has the source for it, but to properly deploy it will still require the native Mac bindings, which you can’t do without a Mac.

Cross-compiler environments could be done, however, using MXE which works with MingW compilers. Download OpenFL and build using openfl build linux on a dummy project to get the C++ generated source code. You might need to create a class that imports literally everything the openfl project has if you want to build the entire library.

Create a makefile in the generated directory that has the following contents:

SRC=[entry point].cpp
OBJ=$(SRC:.c=.o)
EXE=[project].exe
CC=$(CROSS)gcc
CFLAGS=-Wall -O3
LD=$(CROSS)ld
AR=$(CROSS)ar
PKG_CONFIG=$(CROSS)pkg-config
%.o: %.c
    $(CC) $(CFLAGS) -o $@ -c $<

Then cd to the directory in command line and do:

make CROSS=i686-w64-mingw32.static-

This will generate an exe file compiled using MingW and MXE. This is untested, so I am unsure if that will actually work, and good luck using it for anything other than experimentation, because building OpenFL seems a little far fetched since I don’t see any reason why you would want to.

The alternative is to produce an *.ndll file using hxcpp, which would make more sense, but again seems nonsensical since the haxe source already exists and using openfl build [target] will build and generate the source code for the given target anyway. Again, given that you have the tools to do so. Building for iOS requires a Mac and Xcode, for example.

This is until a point where OpenFL can provide build servers for us, but that would be a very expensive endeavour and if such a thing were to happen, expect to pay for the privilege :wink:

References:

  1. mingw.org
  2. MXE (M cross environment)

UPDATE:

This is, as explained above, because hxcpp requires the native bindings required to produce the exe/app/linux file that can then be “executable” because without these native bindings it would be almost impossible.

Again, it may be possibly by using a cross-compiler such as one as I explained above, or by using a command which would use a different compiler:

openfl build windows -linker mingw

Although I’m not actually 100% sure on the command to tell hxcpp to use a different toolchain, so maybe someone can correct me on that.

2 Likes