我在Haxe上编写了自己的协议,数据结构和逻辑的跨平台实现。我如何在iOS和OSX的企业应用程序(使用本机UI)中构建和使用它?
答案 0 :(得分:9)
现状:12.2014; HXCPP-ver。:
3.1.39
〜git
。依赖关系:
hxcpp
使用名为HxModule
的主类创建一个新的Haxe项目。
class HxModule
{
public static function main()
{
Sys.println('Hello from HxModule: "${test()}"');
}
@:headerCode
public static function test():Int
{
return 101;
}
}
build.hxml
-main HxModule
-cp src
-lib hxcpp
# this is for Mac OS X:
-D HXCPP_M64
# this is required on Windows. the "d" stands for debug:
#-D ABI=-MTd
--each
# at this phase we create a binary for tests
-cpp out/cpp/module
--next
# at this phase we create a binary for tests
-cpp out/cpp/module
-D static_link
-D actuate
构建:$ haxe buid.hxml
out/cpp/module/include
- 您必须将其修复为完整路径; {your-haxelib-repo}/hxcpp/{version}/include
- {here-yours}; /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
GNU++11 [-std=gnu++11]
libstdc++ (GNU C++ standard library)
HxModule.a
AppDelegate.m
- > AppDelegate.mm
AppDelegate.mm
:#import "AppDelegate.h"
#import "HxModule.h"
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSLog(@"test: %d", ((int)HxModule_obj::test()));
}
@end
此外,对于自动完成和更好的导航,您可以从目录中添加参考组的Xcode项目:
include
; include
的hxcpp
。在撰写本文时,只有一个可能的问题。可以通过编辑文件{haxelib:hxcpp}/include/hxcpp.h
来解决。只需在文件开头添加几行:
#ifndef HXCPP_H
#define HXCPP_H
// Standard headers ....
// Custom override by @suhinini
#define Class HxcppClass
// Basic mapping from haxe -> c++
typedef int Int;
typedef bool Bool;
// Windows hack
#define NOMINMAX
#ifdef _MSC_VER
#include <typeinfo.h>
namespace hx { typedef ::type_info type_info; }
...
查看// Standard headers ....
。