Haxe hxcpp shell creation for C library

since a couple of days I try to write a Haxe hxcpp wrapper for linenoise , which is programmed in C code; the library is very simple and the title also contains extern C. I follow the snowman macro template, but I cannot get a way to compile the C module and link it to the rest of the project, I am not sure how to proceed.

I have no problem compiling the code as a C object and associating it with the C executable code on my system (OSX el Capitan), so I assume that I am doing something wrong in my haxe project, maybe I cannot really link hxcpp with the C library, using the build process directly from haxe, or I have to manually do it by writing commands on hand.

@:keep @:structAccess @:include('linenoise.h') #if !display @:build(linc.Linc.touch()) @:build(linc.Linc.xml('linenoise')) #end extern class LineNoise { @:native("linenoiseClearScreen") static function linenoiseClearScreen(): Void; } //LineNoise 

Recently, I get this error:

 g++ -o Test-debug -stdlib=libstdc++ -framework Cocoa -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -m64 @/Users/vresko/projects/linenoise/test/cpp/obj/darwin64-debug/all_objs Undefined symbols for architecture x86_64: "_linenoiseClearScreen", referenced from: Test_obj::main() in ab184b9a_Test.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) 

I know this error has several references, but I'm not sure how to solve this problem in the context of haxe hxcpp.

If I use a C ++ wrapper, including hxcpp.h, since the typical linc example makes the same error, the function I declare here (linenoiseClearScreen) is actually a trivial print operation. A.

I also read about other possibilities, such as CFFI for neko, to create a wrapper around the library (maybe I read all about it on the Internet), but I wanted to keep the code static code, if possible, and compatible with all hxcpp goals.

+5
source share
1 answer

it sounds like you are missing a step when setting up dependencies for hxcpp, in your case linenoise. hxcpp does not know about the .c file.

This is clearly missing from the empty template, as the actual dependency is not used.

Anyway, I am the author of https://github.com/snowkit/linc_enet , bindings for ENet for hxcpp. This can help you compare your installation with a more complete example like this.

In this case, ENet, as a dependency, is configured as a special hxcpp git submodule inside the lib folder. It can be found here as part of the built-in toolkit: https://github.com/native-toolkit/enet

What you should pay attention to are the 2 xml defines.xml and files.xml . They mainly describe the dependency for hxcpp. you can literally copy these attachments, adapt the definitions and file list for linenoise.

Also, I would not recommend including linenoise.h directly through @:include in the binding. Linc libraries use an indirect relation at this level (see the linc folder in linc_enet -root) to allow extensions / helpers / for bindings on the C ++ side, without touching the actual dependencies.

If you follow this concept, see linc/linc_enet.xml , where everything is linked for compilation.

+6
source

Source: https://habr.com/ru/post/1237704/


All Articles