#define IMPLEMENT_API
#include <hx/CFFI.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
extern "C" {
value sum(value a, value b)
{
if( !val_is_int(a) || !val_is_int(b) ) return val_null;
return alloc_int(val_int(a) + val_int(b));
}
}
DEFINE_PRIM( sum, 2 );
g++ can't find `hx/CFFI.h`
$ g++ ExternalMath.c -shared -o ../bin/ExternalMath.dll
ExternalMath.c:2:21: fatal error: hx/CFFI.h: No such file or directory
#include <hx/CFFI.h>
^
compilation terminated.
g++ ExternalMath.c -shared -o ../bin/ExternalMath.dll -I c:\alexey\apps\haxe\lib\hxcpp\3,3,49\include
In file included from hx/CFFI.h:124:0,
from ExternalMath.c:2:
hx/CFFILoader.h:58:41: fatal error: mach-o/dyld.h: No such file or directory
#include <mach-o/dyld.h>
^
compilation terminated.
$ g++ ExternalMath.c -shared -o ../bin/ExternalMath.dll -I c:\alexey\apps\haxe\lib\hxcpp\3,3,49\include
/tmp/ccHeQvjk.o:ExternalMath.c:(.rdata$.refptr.val_int[.refptr.val_int]+0x0): undefined reference to `val_int'
/tmp/ccHeQvjk.o:ExternalMath.c:(.rdata$.refptr.alloc_int[.refptr.alloc_int]+0x0): undefined reference to `alloc_int'
/tmp/ccHeQvjk.o:ExternalMath.c:(.rdata$.refptr.alloc_null[.refptr.alloc_null]+0x0): undefined reference to `alloc_null'
/tmp/ccHeQvjk.o:ExternalMath.c:(.rdata$.refptr.val_type[.refptr.val_type]+0x0): undefined reference to `val_type'
collect2: error: ld returned 1 exit status
<xml>
<include name="${HXCPP}\build-tool\BuildCommon.xml"/>
<files id="prime">
<file name="include/ExternalMath.cpp" />
</files>
<target id="default" output="ExternalMath" tool="linker" toolid="dll">
<outdir name="../bin/" />
<files id="prime"/>
</target>
</xml>
My minimal DLL file
#ifndef STATIC_LINK
#define IMPLEMENT_API
#endif
#if defined(HX_WINDOWS) || defined(HX_MACOS) || defined(HX_LINUX)
// Include neko glue....
#define NEKO_COMPATIBLE
#endif
#include <hx/CFFIPrime.h>
int sum(int a, int b)
{
return a + b;
}
DEFINE_PRIME2(sum);Single HAXE class which use it:
class ExternalLibrary {
static var sumFunc:Int->Int->Int = cpp.Lib.load("ExternalMath.dll","sum",2);
public static function main() {
trace("Sum 2 + 3 = " + sumFunc(2, 3));
}
}And command line output:$ ExternalLibrary-debug.exe ExternalLibrary.hx:15: Sum 2 + 3 = 5