How can I include a c++ library directory to hxcpp build process?

How can I add compiler flags via project.xml or where is hxcpp_config.xml? I need to include cpp files and I don’t want to use absolute path, because I don’t want to edit the whole cpp Library.

@:include(“LinearMath/btScalar.h”)
@:native("::btTypedObject")
@:structAccess
@:unreflective

The LinearMath folder is in another folder, and I want to include this to build the library cpp files.

I’m really sorry, but I got it now (after searching for hours). :wink:

If you want to use your own hxcpp_config.xml, type in the console:

haxelib run hxcpp

A hxcpp_config.xml will be created in the Users Directory (talking now about win 7).

 <!-- Compiling on windows ... -->
 <compiler id="MSVC" if="windows">
    <!-- Example adding a build flag -->
    <flag value = "-IC:/path/>
 </compiler>

Or with @:Buildxml
http://www.wighawag.com/blog/2014/12/Hxcpp-extern

[…]

As of haxe 3.2, you can include relative to the .hx file, eg:
@:include("./…/include/LinearMath/btScalar.h")

Hugh

Thank you. One more question … I read the whole Internet and I found some answers from you too related to this topic :wink:

I was able to include cpp files and I tested some functions/classes of the library (bullet-physics), and they work. E.g. when I trace an instanced Class from the library I get back a Pointer. That means it’s there and the library is included (I think).

But when I call a function or class that in turn call this function btAlignedAllocInternal(unsigned int,int) the compiler complains about LNK2019 Error. I don’t unterstand that. Maybe a 32-Bit/64-Bit issue? Unfortunately I can’t test it out, because when I compile for 64 bit I get a Null Function Pointer Exception.

I have not really an idea of coding cpp, I would like to know what could be wrong. But perhaps it’s because of the library itself.

Sorry for my bad english.

If it’s a linker error then you most likely didn’t add the required library file for linking, the h files are not enough.

You need a @:buildXml and something along the lines of <compilerflag value='-lmylibthingy'/> I think.

I already have a @:buildXml with compilerflag value with the path to the source files. But I don’t really understand where the lib is? It compiles and generates the lib and then wants to link this lib? But where is the lib then, so I can include it?

I have buildXml with

files id=‘haxe’ compilerflag value=’-IC:/Users/marcus/haXeProjekte/BulletPhysicsTest/src/cpp/bullet …

And that works, because the source files are found. But I don’t know where the lib is then.

// files id=’_ lib _’ compilerflag value=’- ???

I’m sorry, I am a cpp noob. :smile:

Or is it then in Application-Main.lib and I just have to include that? That would be really amazing. :slight_smile:

(tags not allowed)

EDIT:

I really don’t know how to link the library. From my understanding I thought it would be compiled with the other openfl and my haxe source an is in ApplicationMain.lib. I can’t find other libs in my project.

That is pretty close. see:


for an example.

Another trick you can use is put the bullet-time library into a haxelib, and then you can use the “${haxelib:myhaxelibname}” in any of the xml injection code to allow the path to be changed on different machines.

Hugh

That helped A LOT ! :smile:

Thank you guys.

I thought the libs where built by compiling the haxe bindings because they include the cpp-sources as well, but I had to compile the libs with VS first and include them then. Searched the whole internet in the absolute wrong places haha. Name Mangling, 32-64 bit issue … NO I HAD TO INCLUDE THE LIBRARYs, I could bite me in my ass.

Away3D OpenFL Port and Bullet-Physics, nice.

If somebody needs Cpp 3D Physics:

Now I have another problem.

extern class BtVector3 {
@:native(“new btVector3”)
public static function create(x:BtScalar = 0, y:BtScalar = 0, z:BtScalar = 0):cpp.Pointer;
public function setX(x:BtScalar):Void;
}

When I want to call btvector.setX() it gives an error.

cpp.Pointer haxebullet.BtVector3 has no field setX

EDIT:
Hm. I saw your Video WWX 2014, Hugh. And updated hxcpp to newest dev build + haxe nightly build. I really don’t know why it does not run. I use FlashDevelop and fdbuild.exe runs "haxlib run lime build “project.xml” -debug -Dfdb.

You might be missing the @:structAccess meta to work nicely with cpp.Pointer and extern.

However, skip forward a year to wwx2015 and you will see that the “cpp::Reference” is a nicer way of dealing with pointers.

See:

Where you would use “BtVector3Ref” in your code everywhere instead of cpp.Pointer<BtVector3>, and the “.” syntax should work.

It may also be possible to use “BtVectrorStruct” if the native class does not have a constructor/destructor that needs to be called. Then you do no need new/delete.

Hugh

Thanks. I will try that out.

But this is some code from the Haxe Bindings, and it should work, but It doesn’t.

// ------------------------------------------------------ #if js @:native('Ammo.btVector3') #elseif cpp @:include("LinearMath/btVector3.h") @:native("::btVector3") @:structAccess @:unreflective #end extern class BtVector3 { #if js public function new(x:BtScalar = 0, y:BtScalar = 0, z:BtScalar = 0):Void; #elseif cpp @:native("new btVector3") public static function create(x:BtScalar = 0, y:BtScalar = 0, z:BtScalar = 0):cpp.Pointer; #end public function setX(x:BtScalar):Void; public function setY(y:BtScalar):Void; public function setZ(z:BtScalar):Void; public function setW(w:BtScalar):Void; public function x():BtScalar; public function y():BtScalar; public function z():BtScalar; public function w():BtScalar; public function length():BtScalar; public function normalize():BtVector3; }

The compiler knows not about the functions. By the way: how do i format Syntax Code here?

Great, it works now. Tried your Example

var std = StdString.create(“my std::string”);
trace( std.value.size() );
std.destroy();

Had to use “value”, not directly the pointer.