I am attempting to build a very simple example of an extern I am creating using Haxe using a simple C++ class/header file:
My folder structure looks like this:
BasicCppExtern
bin/
include/test.h
lib/Test.lib
src/Main.hx
src/Test.hx
My Test.hx file looks like this:
@:include("../../include/test.h")
@:structAccess
@:native("TestClass")
extern class Test
{
@:native("new TestClass")
public static function create():Pointer<Test>;
@:native("output")
public function output(text:ConstPointer<Char>):Void;
}
Followed by my main class, which injects some XML to link everything together:
using cpp.NativeString;
@:buildXml('
<set name="LIB_BCPPEXTERN" value="../" />
<target id="test.ndll" tool="linker" toolid="${STD_MODULE_LINK}" output="bin/basic/">
<files id="files"/>
<outdir name="../ndll/windows/"/>
<section unless="static_link">
<section if="windows">
<lib name="${LIB_BCPPEXTERN}lib/Test.lib" />
</section>
</section>
</target>
<files id="files">
<compilerflag value="-Iinclude/" />
<compilerflag value="-D__WIN32__" />
<compilerflag value="-Ddebug" />
<compilerflag value="-Dstatic_link" />
</files>
')
@:keep class Main
{
static function main()
{
var t = Test.create();
t.value.output("This is some text".c_str());
}
}
It compiles successfully, and I’m thinking of testing this further with larger libraries as I go. But once it gets to the linker, hxcpp does not seem to get the paths to the *.lib
files correctly, getting the LNK2019 errors which as far as I am concerned is normally a problem with the *.lib
. I built the Lib file using Debug
configuration, so does that mean there is a special flag I need to use for it to link properly?
However, if it helps, I have a screenshot of the errors from the linker here:
It baffles me that even the simplest of tasks causes me errors.