如何从Haxe创buildiOS和OSX库并在本地应用程序中使用它?

我在Haxe上编写了自己的协议,数据结构和逻辑的跨平台实现。 如何在iOS和OSX的企业应用程序(使用本机用户界面)中构build和使用它?

如何从Haxe创buildiOS- / OSX-库并在本地应用程序中使用它

现状:12.2014; HXCPP-ver .: 3.1.39

依赖: hxcpp

1. Haxe – >图书馆

创build一个名为HxModule主类的Haxe项目。

SRC / HxModule.hx

 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 

build立: $ haxe buid.hxml

2. Xcode-project < – Library

  1. 创build一个新的Xcode项目。 它可以用于OSX或iOS,Application或Cocoa Framework。
  2. 在'项目'/'构build设置'/'标题searchpath'添加path依赖关系:(所有path必须是完整/非相对recursion
    1. out/cpp/module/include – 你必须修复它到完整path ;
    2. {your-haxelib-repo}/hxcpp/{version}/include – {here-yours};
    3. /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
  3. 在'Project'/'Build Settings'/'Apple LLVM 6.0 – Language – C ++'中更改值:
    • 'C ++语言Dialect'= GNU++11 [-std=gnu++11]
    • 'C ++标准库'= libstdc++ (GNU C++ standard library)
  4. 在“项目”/“构build阶段”/“与库的链接二进制文件”中:
    • HxModule.a
  5. 重命名文件: AppDelegate.m – > AppDelegate.mm
  6. 编辑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-project 参考组

  • include Haxe的产出;
  • include从haxelib hxcpp

可能的问题:

当时这个文本只写了一个可能的问题。 可以通过编辑文件{haxelib:hxcpp}/include/hxcpp.h来解决。 只需在文件的开头添加几行即可:

{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 ....

示例项目 。

    Interesting Posts