Hxcpp cross compilation MacOS to Linux

Introduction

Recently, when I was looking for this answer, I encountered some problems, and the relevant documentation was also missing in HXCPP.
I hope to leave the basic tutorial here.
It is designed to help Mac users cross-compile HXCPP to Linux targets.

1. Use Linux cross compiler

Linux cross compiler download url: https://github.com/messense/homebrew-macos-cross-toolchains

Generally speaking, do not need to let the environment in the PATH, only need to let HXCPP to know, please download the corresponding Linux environment in the above address cross compiler, for example, x86_64, you can directly download x86_64-unknown-linux-gnu-x86 _64-darwin version; after downloading, directly decompress to the corresponding directory placement.

2. Config ./hxcpp_config.xml

<!-- 64bit -->
<set name="HXCPP_XLINUX64_CXX" value="/Users/rainy/Documents/SDK/x86_64-unknown-linux-gnu/bin/x86_64-unknown-linux-gnu-g++" />
<set name="HXCPP_XLINUX64_STRIP" value="/Users/rainy/Documents/SDK/x86_64-unknown-linux-gnu/bin/x86_64-unknown-linux-gnu-strip" />
<set name="HXCPP_XLINUX64_RANLIB" value="/Users/rainy/Documents/SDK/x86_64-unknown-linux-gnu/bin/x86_64-unknown-linux-gnu-ranlib" />
<set name="HXCPP_XLINUX64_AR" value="/Users/rainy/Documents/SDK/x86_64-unknown-linux-gnu/bin/x86_64-unknown-linux-gnu-ar" />
<!-- 32bit, Still need it? -->
<set name="HXCPP_XLINUX32_CXX" value="/Users/rainy/Documents/SDK/x86_64-unknown-linux-gnu/bin/x86_64-unknown-linux-gnu-g++" />
<set name="HXCPP_XLINUX32_STRIP" value="/Users/rainy/Documents/SDK/x86_64-unknown-linux-gnu/bin/x86_64-unknown-linux-gnu-strip" />
<set name="HXCPP_XLINUX32_RANLIB" value="/Users/rainy/Documents/SDK/x86_64-unknown-linux-gnu/bin/x86_64-unknown-linux-gnu-ranlib" />
<set name="HXCPP_XLINUX32_AR" value="/Users/rainy/Documents/SDK/x86_64-unknown-linux-gnu/bin/x86_64-unknown-linux-gnu-ar" />

3. Install zstd tools

If it already exists in the computer environment, installation is not necessary.

zstd download url: https://github.com/facebook/zstd/releases/tag/v1.5.5

Download it and unzip it, enter the directory, and execute the command.

make && make install

4. Config HXML file

--cpp bin/cpp
--main Main
-D linux
-D HXCPP_X86

5. Compiler

haxe build.hxml

Note that the MacOS security system will intercept the operation of the command, need to compile several times, the interception program needs to go to the security settings to allow it to execute.

6. Get a Linux application

Thanks all.

5 Likes