$ openfl create extension TestExtension
Error: Could not find sample “extension” in project “openfl”
At the same time:
$ lime create extension test2
seems to work. What am I doing wrong?
Not sure if it’s a good idea to ask in the same topic, but I also failed to find examples of adding native libraries (I need google protobuf for cpp/linux target) and I also want to have a static build for my final project. It seems possible, but may be there are better ways to achieve it besides extensions…?
If you need your own C++ code, I’d recommend an extension. Currently extensions are not designed to be linked statically, though. This could be done for sure (there’s nothing technical that prevents it) but the tools are not set up currently to expect it and link differently for it.
openfl create extension not working must be a bug, lime create extension is fine, and does the same thing. That should give an example for compiling a standalone C++ binary that’s available for projects to use. lime rebuild <path to extension or haxelib name> linux should recompile the extension, then <include path="to/extension" /> or <haxelib name="of-extension-if-its-a-haxelib" /> will include both the code and C++ library from your extension in a project
Thank you very much for such a clear explantation. Now at least I can try it:) I guess I’ll have a lot of fun trying to link with external libraries (for google protobuf for example). Can you give me some directions / example projects / documentation to look at before?
I think you could lime rebuild <name or path of extension> windows -static to build a static (instead of a dynamic) version
Next, the key would be linking this when building. You probably would need to do a static build of your application. For Lime 2 (which OpenFL -Dnext uses) I confirmed static build support for Windows, Mac and Linux. I think this might actually work out of the box.
I have not tried compiling the Lime 1 legacy binaries (which OpenFL native uses by default, currently) as a static build, but it can’t be (too?) complicated. Would be happy to help if someone is interested in taking a look
RunLibs.cpp:(.text+0x15): undefined reference to `std_register_prims'
RunLibs.cpp:(.text+0x1a): undefined reference to `regexp_register_prims'
RunLibs.cpp:(.text+0x1f): undefined reference to `zlib_register_prims'
which are the errors for each *.dso files in final dynamic build. My guess is these *.dso could also be built as *.a files on linux, but I’m lost… how to to build these? somehting related to rebuilding hxcpp maybe?
$ openfl build linux -static -Dnext
...sources/lime/ndll/Linux/liblime.a(5c4c0827_inflate.o): In function `inflateReset':
inflate.c:(.text+0x280): multiple definition of `inflateReset'
/usr/lib/haxe/lib/hxcpp/3,1,68/lib/Linux/libzlib.a(69ebc970_inflate.o):inflate.c:(.text+0x220): first defined here
/home/ds/sources/lime/ndll/Linux/liblime.a(5c4c0827_inflate.o): In function `inflateInit2_':
.... # output for various zlib functions
attempt to exclude libzlib.a and run linking manually:
$ g++ -o Main -rdynamic -m32 @obj/linux-stat//all_objs /usr/lib/haxe/lib/hxcpp/3,1,68/lib/Linux/libstd.a /usr/lib/haxe/lib/hxcpp/3,1,68/lib/Linux/libregexp.a .../../../sources/lime/ndll/Linux/liblime.a /usr/lib/haxe/lib/hxcpp/3,1,68/lib/Linux/liblinuxcompat.a -lpthread -lrt ApplicationMain.a -ldl
obj/linux-stat/3c79f9bd_Main.o: In function `main':
Main.cpp:(.text.startup+0x25): undefined reference to `zlib_register_prims'
ApplicationMain.a(f2885469_RunLibs.o): In function `hxRunLibrary':
RunLibs.cpp:(.text+0x1f): undefined reference to `zlib_register_prims'
collect2: error: ld returned 1 exit status
HXCPP includes zlib, because some of the Haxe standard methods use zip compression. However, Lime also includes zlib. As a result, we need to include only one or the other, not both. I think I may have resolved this problem for iOS (which is always a statically-linked build), see:
Perhaps this could be if="ios || static" or if="ios || static_link" (see if one of those works), there might probably be another place that includes the “zlib” NDLL (maybe “include.xml”), where we would want to exclude the HXCPP version, since we’re compiling it into the Lime static lib instead
Did that already:)) now trying to find out where did this came from:
openfl build linux -static -Dnext
...
ApplicationMain.a(f2885469_RunLibs.o): In function `hxRunLibrary':
RunLibs.cpp:(.text+0x1f): undefined reference to `zlib_register_prims'
collect2: error: ld returned 1 exit status
Looks I’m almost there anyway thanks to your help:)
ApplicationMain.a(f2885469_RunLibs.o): In function `hxRunLibrary':
RunLibs.cpp:(.text+0x1f): undefined reference to `zlib_register_prims'
collect2: error: ld returned 1 exit status
Hmm, well the idea (normally) is that instead of including libzlib.a, we manually compile in the file that has zlib_register_prims along with our own zlib version. Lime uses a newer zlib than HXCPP, so this allows everything to use the one, newer version of zlib.