我有一个跨平台的实现自己的协议,数据结构和逻辑写在哈克斯.如何在iOS和OSX的企业级应用程序(带有本地UI)中构建和使用它?
发布于 2014-12-07 14:31:21
如何从Haxe创建iOS- /OSX库并在本机应用程序中使用
现状: 12.2014;HXCPP.:
3.1.39~git. 依赖关系:hxcpp
1. Haxe ->库
使用名为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构建:$ haxe buid.hxml
2. Xcode-项目<-库
out/cpp/module/include -你必须把它修正成完整的路径;{your-haxelib-repo}/hxcpp/{version}/include -{这里-你的};/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/includeGNU++11 [-std=gnu++11]libstdc++ (GNU C++ standard library)HxModule.aAppDelegate.m -> AppDelegate.mmAppDelegate.mmAppDelegate.mm
#import "AppDelegate.h"
#import "HxModule.h"
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSLog(@"test: %d", ((int)HxModule_obj::test()));
}
@end此外,对于自动完成和更好的导航,您可以将目录中的引用组添加到Xcode-project中:
include;include从哈克斯利布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 ....__。
示例项目。
https://stackoverflow.com/questions/27343675
复制相似问题