Use haxe built lib in cpp project

141 views
Skip to first unread message

Bruno Santos

unread,
Mar 31, 2015, 12:29:59 PM3/31/15
to haxe...@googlegroups.com
Hi there,

I'm trying to build a lib in haxe and then use it in cpp target.

This were the links I was able to find that came closer of what I want to make:
http://www.wighawag.com/blog/2014/12/Hxcpp-extern
http://stackoverflow.com/questions/27343675/how-to-create-ios-osx-library-from-haxe-and-use-it-in-native-application
https://github.com/fzzr-/hx.NativeModule

I'm currently stuck on the part of actually using the haxe-compiled-lib in a cpp project.

The errors I'm getting are:
Error   6   error LNK2001: unresolved external symbol "public: virtual class Dynamic __thiscall hx::Object::__Field(class String const &,bool)" (?__Field@Object@hx@@UAE?AVDynamic@@ABVString@@_N@Z)    D:\Projects\Code\hx.module.test\project\build\haxetest.obj  PromoHxTest
Error   7   error LNK2001: unresolved external symbol "public: virtual class Dynamic __thiscall hx::Object::__SetField(class String const &,class Dynamic const &,bool)" (?__SetField@Object@hx@@UAE?AVDynamic@@ABVString@@ABV3@_N@Z)   D:\Projects\Code\hx.module.test\project\build\haxetest.obj  PromoHxTest
Error   8   error LNK2001: unresolved external symbol "public: virtual class Dynamic __thiscall hx::Anon_obj::__Field(class String const &,bool)" (?__Field@Anon_obj@hx@@UAE?AVDynamic@@ABVString@@_N@Z)    D:\Projects\Code\hx.module.test\project\build\haxetest.obj  PromoHxTest
Error   9   error LNK2001: unresolved external symbol "public: virtual class Dynamic __thiscall hx::Anon_obj::__SetField(class String const &,class Dynamic const &,bool)" (?__SetField@Anon_obj@hx@@UAE?AVDynamic@@ABVString@@ABV3@_N@Z)   D:\Projects\Code\hx.module.test\project\build\haxetest.obj  PromoHxTest
Error   10  error LNK2001: unresolved external symbol "public: virtual class Dynamic __thiscall cpp::IteratorBase::__Field(class String const &,bool)" (?__Field@IteratorBase@cpp@@UAE?AVDynamic@@ABVString@@_N@Z)  D:\Projects\Code\hx.module.test\project\build\haxetest.obj  PromoHxTest
Error   11  error LNK2001: unresolved external symbol "public: virtual class Dynamic __thiscall hx::ArrayBase::__Field(class String const &,bool)" (?__Field@ArrayBase@hx@@UAE?AVDynamic@@ABVString@@_N@Z)  D:\Projects\Code\hx.module.test\project\build\haxetest.obj  PromoHxTest
Error   12  error LNK2001: unresolved external symbol "public: virtual class Dynamic __thiscall hx::Class_obj::__Field(class String const &,bool)" (?__Field@Class_obj@hx@@UAE?AVDynamic@@ABVString@@_N@Z)  D:\Projects\Code\hx.module.test\project\build\haxetest.obj  PromoHxTest
Error   13  error LNK2001: unresolved external symbol "public: virtual class Dynamic __thiscall hx::Class_obj::__SetField(class String const &,class Dynamic const &,bool)" (?__SetField@Class_obj@hx@@UAE?AVDynamic@@ABVString@@ABV3@_N@Z) D:\Projects\Code\hx.module.test\project\build\haxetest.obj  PromoHxTest
Error   14  error LNK2001: unresolved external symbol "public: virtual class Dynamic __thiscall hx::EnumBase_obj::__Field(class String const &,bool)" (?__Field@EnumBase_obj@hx@@UAE?AVDynamic@@ABVString@@_N@Z)    D:\Projects\Code\hx.module.test\project\build\haxetest.obj  PromoHxTest
Error   15  error LNK2001: unresolved external symbol "public: virtual class Dynamic __thiscall hx::Interface::__Field(class String const &,bool)" (?__Field@Interface@hx@@UAE?AVDynamic@@ABVString@@_N@Z)  D:\Projects\Code\hx.module.test\project\build\haxetest.obj  PromoHxTest
Error   16  error LNK2001: unresolved external symbol "public: virtual class Dynamic __thiscall hx::Interface::__SetField(class String const &,class Dynamic const &,bool)" (?__SetField@Interface@hx@@UAE?AVDynamic@@ABVString@@ABV3@_N@Z) D:\Projects\Code\hx.module.test\project\build\haxetest.obj  PromoHxTest
Error   17  error LNK1120: 11 unresolved externals  D:\Projects\Code\hx.module.test\project\build\Debug\PromoHxTest.exe PromoHxTest

I've committed my test project to this repo: https://github.com/bmfs/hx.module.test

Any suggestions, idea on what is missing?
Am I supposed to include hxcpp includes in the cpp project at all?

Thanks in advance,
Bruno


Bruno Santos

unread,
Mar 31, 2015, 2:30:30 PM3/31/15
to haxe...@googlegroups.com
Answering my own question, yes I should include hxcpp headers.

I've commited my changes to the repo ( https://github.com/bmfs/hx.module.test ).

Basically followed http://www.wighawag.com/blog/2014/12/Hxcpp-extern example closely and declared PromoHx_obj on the cpp side.

I initially tried this, but I didn't know how to pass the string parameters on the methods.
Found out I could use ConstPointer<Char> on the haxe side, and then Pointer<char> on the cpp side.

The next challenge I'll try to tackle is how to pass callbacks to the haxe side.

Bruno Santos

unread,
Apr 7, 2015, 12:58:05 PM4/7/15
to haxe...@googlegroups.com
Getting back to this experiments.

I've added #include <hxcpp.h>;  to https://github.com/bmfs/hx.module.test/blob/master/project/src/haxetest.cpp

When compiling with Visual studio I getting the errors I mentioned initially:

Error   6   error LNK2001: unresolved external symbol "public: virtual class Dynamic __thiscall hx::Object::__Field(class String const &,bool)" (?__Field@Object@hx@@UAE?AVDynamic@@ABVString@@_N@Z)    D:\Projects\Code\hx.module.test\project\build\haxetest.obj  PromoHxTest
Error   7   error LNK2001: unresolved external symbol "public: virtual class Dynamic __thiscall hx::Object::__SetField(class String const &,class Dynamic const &,bool)" (?__SetField@Object@hx@@UAE?AVDynamic@@ABVString@@ABV3@_N@Z)   D:\Projects\Code\hx.module.test\project\build\haxetest.obj  PromoHxTest
Error   8   error LNK2001: unresolved external symbol "public: virtual class Dynamic __thiscall hx::Anon_obj::__Field(class String const &,bool)" (?__Field@Anon_obj@hx@@UAE?AVDynamic@@ABVString@@_N@Z)    D:\Projects\Code\hx.module.test\project\build\haxetest.obj  PromoHxTest
Error   9   error LNK2001: unresolved external symbol "public: virtual class Dynamic __thiscall hx::Anon_obj::__SetField(class String const &,class Dynamic const &,bool)" (?__SetField@Anon_obj@hx@@UAE?AVDynamic@@ABVString@@ABV3@_N@Z)   D:\Projects\Code\hx.module.test\project\build\haxetest.obj  PromoHxTest
Error   10  error LNK2001: unresolved external symbol "public: virtual class Dynamic __thiscall cpp::IteratorBase::__Field(class String const &,bool)" (?__Field@IteratorBase@cpp@@UAE?AVDynamic@@ABVString@@_N@Z)  D:\Projects\Code\hx.module.test\project\build\haxetest.obj  PromoHxTest
Error   11  error LNK2001: unresolved external symbol "public: virtual class Dynamic __thiscall hx::ArrayBase::__Field(class String const &,bool)" (?__Field@ArrayBase@hx@@UAE?AVDynamic@@ABVString@@_N@Z)  D:\Projects\Code\hx.module.test\project\build\haxetest.obj  PromoHxTest
Error   12  error LNK2001: unresolved external symbol "public: virtual class Dynamic __thiscall hx::Class_obj::__Field(class String const &,bool)" (?__Field@Class_obj@hx@@UAE?AVDynamic@@ABVString@@_N@Z)  D:\Projects\Code\hx.module.test\project\build\haxetest.obj  PromoHxTest
Error   13  error LNK2001: unresolved external symbol "public: virtual class Dynamic __thiscall hx::Class_obj::__SetField(class String const &,class Dynamic const &,bool)" (?__SetField@Class_obj@hx@@UAE?AVDynamic@@ABVString@@ABV3@_N@Z) D:\Projects\Code\hx.module.test\project\build\haxetest.obj  PromoHxTest
Error   14  error LNK2001: unresolved external symbol "public: virtual class Dynamic __thiscall hx::EnumBase_obj::__Field(class String const &,bool)" (?__Field@EnumBase_obj@hx@@UAE?AVDynamic@@ABVString@@_N@Z)    D:\Projects\Code\hx.module.test\project\build\haxetest.obj  PromoHxTest
Error   15  error LNK2001: unresolved external symbol "public: virtual class Dynamic __thiscall hx::Interface::__Field(class String const &,bool)" (?__Field@Interface@hx@@UAE?AVDynamic@@ABVString@@_N@Z)  D:\Projects\Code\hx.module.test\project\build\haxetest.obj  PromoHxTest
Error   16  error LNK2001: unresolved external symbol "public: virtual class Dynamic __thiscall hx::Interface::__SetField(class String const &,class Dynamic const &,bool)" (?__SetField@Interface@hx@@UAE?AVDynamic@@ABVString@@ABV3@_N@Z) D:\Projects\Code\hx.module.test\project\build\haxetest.obj  PromoHxTest
Error   17  error LNK1120: 11 unresolved externals  D:\Projects\Code\hx.module.test\project\build\Debug\PromoHxTest.exe PromoHxTest

The same steps on a mac machine, and everything goes well.
On windows, dumped the generated library symbols with `nm` and it doesn't include the missing symbols Visual Studio  complains about.

Can this be some kind of bug when generating the static lib with visual studio?

For refence, my current steps are:

1. build hxcpp:
 cd $HXCPP/projects
 neko build.n static-windows -debug -DABI=-MTd

2. build haxe project:
 cd $PROJECT_ROOT/promohx
 haxe build.hxml

3. build cpp project:
 cd $PROJECT_ROOT/project/build
 cmake ..
 open visual studio
 compile

Hugh

unread,
Apr 7, 2015, 9:22:26 PM4/7/15
to haxe...@googlegroups.com
If your visual studio project includes hxcpp.h, then the compile flags need to match the compile flags used by HXCPP when compiling generated code.
Particularly, the new versions of the haxe compiler #defines HXCPP_API_LEVEL=321 when generating the haxe lib.  You need to match this define in your project.

Hugh
Reply all
Reply to author
Forward
0 new messages