Compiling windows cpp from linux using minGW, Its Possible!

I tried it, compile flags are not being pushed to the haxeArgs. Even the code on “-Dno_console” it does not appear on final.hxml file.

That’s fine, basically, calling haxe generates the C++ sources, then calling haxelib run hxcpp compiles it. What we need is to pass the correct arguments to HXCPP in order to compile it for Windows instead of Linux :slight_smile: (the sources are the same no matter the target)

Yhea, I believe i have done it right in the WindowsPlatform.hx in tools, the build went ok. It creates all source files within Export/Windows but still builds Linux. This are the edits I made:

private var enableMingw:Bool;
.
.
.
if (project.targetFlags.exists ("neko")) {

    targetType = "neko";

} else if (project.target != PlatformHelper.hostPlatform && PlatformHelper.hostPlatform != Platform.LINUX){

    targetType = "neko";

} else if (project.targetFlags.exists ("nodejs")) {

    targetType = "nodejs";

}  else {

    if (project.target != PlatformHelper.hostPlatform){

        enableMingw = true;

    }

    targetType = "cpp";

}

I notice that haxeArgs were local var within “build” function so I added a condition in it to include mingw args

if (enableMingw) {

    haxeArgs.push ("-D");

    haxeArgs.push ("mingw");

    flags.push ("-Dmingw");

 }

Ok, its now working with “-Dtoolchain=mingw_linux_host”. Everything compiled well, and its now executable.

I made a pull request at github on lime and hxcpp.

If both gets accepted everybody can now cross-compile from Linux-64bit to windows-32, how’s for that! :smile:

I will add support to detect Linux-32bit and other mingw-path for other Linux distribution. And maybe Windows to Linux, one at a time of course, or if others could do it, that would be better :smile:

Cross distribution along different linux system appears to be a bit tricky than it sounds, it appears that the Mingw name of

  1. libgcc
  2. stdc++ and
  3. libwinpthread

varies across linux systems. Is there a way to which we could make lime to automatically check and copy these dependencies?

when I checked the hxcpp xml’s we should tell explicitly exact file to copy (complete with name) - so its is not a good thing to do it there.

Does it work without copying these libraries next to the binary?

It does not work in Wine-32 and Windows-OS, the application complains about missing the above dlls.

But when I copy those files, it even worked on Win10 machine, thats pretty impressive for a cross-desktop build :smile:

I’m not sure I like that restriction. I was actually thinking of just building directly with msvc because of my frustrations with hxcpp and XML files, but then, what do I know? I think there needs better documentation of the build tool, or just a better build tool altogether.

I like HXCPP over CMake, make and a lot of other cross-platform build tools that just start creating headaches – especially when you are running on Windows, Mac and Linux environments

We have the ability to improve the HXCPP build tool if there are issues. Yeah, there isn’t much documentation, I look at NME’s or Lime’s Build.xml for hints on how to use it

Compiling everything from a single platform is just so powerful! :smile:

I am now in Ubuntu, and will try everything there. I will let you guys know what would the results be.

Whoa! compiling in Ubuntu is much easier than in Fedora, yhea, you just got to enable repositories and install mingw-w64 in just one line:

sudo apt-get install mingw-w64

and Ubuntu does all for you, it automatically downloads and install all mingw binaries, headers and other includes files for both 64bit and 32bit cross compilation.

But there are some code I could not execute from WindowsPlatform.hx:

for (dependency in project.dependencies) {
    if (StringTools.endsWith (dependency.path, ".dll")) {
        var fileName = Path.withoutDirectory (dependency.path);
        FileHelper.copyIfNewer (dependency.path, applicationDirectory + "/" + fileName);
    }
 }

If I understood correctly, the code above copies hxcpp dll files to bin directory, but it does not, I think

 dependency.path

or

FileHelper.copyIfNewer ()

is a Windows only code? can we update it to become platform independent?

Both of these should be platform independent. Are you have trouble with standard “lime.ndll” type files being copied, or some additional file, like from an extension?

Glad to know they are platform independent :slight_smile:

When I am on Windows, hxcpp dlls (zlib.dll, std.dll, etc) are automatically copied. But on Linux, only lime.ndll is copied.

Those are flagged as if="cpp" in the Lime include.xml, so perhaps at that point of processing, “cpp” is not defined? (since cross-platform assumes Neko by default)

Is it this one

targetType = "cpp"

I have already made updates to WindowsPlatform.hx to compile through mingw when doing cross-platform.

Openfl automatically generates:

Export/Windows/cpp

Check from final and release.hxml shows “cpp”

Probably something in ProjectXMLParser or HXProject, maybe

I see, I will try to investigate on those files.

It’s in lime/project/ProjectXMLParser.hx line 82 that neko is set for cross-platform build.

Thanks! That narrows down things to look for. :smile:

You guys rock! its on the lime/project/ProjectXMLParser.hx line 82. Now things work as they do

Compilation Host:

  1. Fedora
  2. Ubuntu

Tested on:

  1. Wine
  2. Windows 7
  3. WIndows 10

Apps Tested

  1. BunnyMark
  2. SimpleOpenGLView
  3. AddingAnimation
  4. My own build

So far cross-compilation from Linux to Windows work as they do when compiling to Windows.

Next up:

  1. Replicate in:
    a. Debian
    b. Linux mint
    c. OpenSUSE
    d. Mageia

  2. Compile with msc++

1 Like