4

I try to compile a commandline version of my Haxe program such that it can be used on other computers. These computers do not necessarily have Haxe installed - so I need to create a static linked program. I tried compiling such a version of my program with:

haxe -main mj.MJ -cpp outCpp -D HXCPP_M64 -D static_link

However the result is dynamically linked:

$ file outCpp/MJ
MJ: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, ...

and in consequence the executables are not working on computers that do not have these libraries installed:

$ ./MJ
./MJ: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by ./MJ)

So obviously "-D static_link" is not enough. I then added

package mj;

#if cpp
import cpp.link.StaticStd;
#end

(compare Haxe - Create a C++ Stand-alone executable) to mj/MJ.hx file. After re-executing:

haxe -main mj.MJ -cpp outCpp -D HXCPP_M64 -D static_link

the file is still dynamically linked ... what else do I need to do on Linux?

P.S.:

$ haxe -version
3.4.2
Gama11
  • 31,714
  • 9
  • 78
  • 100
quant
  • 2,184
  • 2
  • 19
  • 29
  • 2
    Fyi, it's spelled "Haxe", not "HaXe". It was changed around 5 years ago. :) – Gama11 Nov 29 '17 at 12:16
  • ah tks for the update – quant Nov 29 '17 at 12:33
  • 1
    Regarding the actual question - I don't have the answer, but `mj.MJ` is probably leftover from a previous compilation, as `-D static_link` produces a statically linked _library_ (should be called something like `libmj.MJ.a`) and no executable at all. – Gama11 Nov 29 '17 at 12:50

1 Answers1

2

The Haxe standard library (HXCPP) on the C++ target used dynamically linked libraries for standard features (such as "zlib" and the "std" library) unless you used -D static_link in older versions, but starting with Haxe 3.4, these are always statically linked.

In current releases, -D static_link still affects third-party "NDLL" libraries, such as the Lime library.

I personally use an older version of Linux (like Ubuntu 12.04 or 14.04) to build for distribution, due to differences in glibc on older Linux systems (or distributions that tend to use an older glibc, such as CentOS).

If you want, try experimenting with changing the HXCPP toolchain for Linux to enable a static libstdc++ library if="static_link" and share the results here or on the Haxe community forum.

Joshua Granick
  • 1,017
  • 6
  • 6