问题描述
我在Haxe上编写了自己的协议,数据结构和逻辑的跨平台实现。如何在iOS和OSX的企业应用程序(使用本机UI)中构建和使用它?
I have an crossplatform implementation of own protocol, data-structures and logic written on Haxe. How I can build and use it in my enterprise-application (with native UI) for iOS and OSX?
推荐答案
如何创建来自Haxe的iOS- / OSX-库并在本机应用程序中使用它
How to create iOS- / OSX- library from Haxe and use it in native application
依赖关系: hxcpp
1。 Haxe - > Library
使用名为 HxModule
的主类创建一个新的Haxe项目。
1. Haxe -> Library
Create a new Haxe-project with main class named HxModule
.
class HxModule
{
public static function main()
{
Sys.println('Hello from HxModule: "${test()}"');
}
@:headerCode
public static function test():Int
{
return 101;
}
}
build.hxml
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
- 创建一个新的Xcode项目。它可以用于OSX或iOS,Application或Cocoa Framework。
- 在'Project'/'Build Setting'/'Header Search Paths'中添加依赖项的路径:(所有路径必须是完整/不相对和递归)
-
out / cpp / module / include
- 您必须将其修复为完整路径; -
{your-haxelib-repo} / hxcpp / {version} / include
- {here-yours}; -
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault .xctoolchain / usr / include
out/cpp/module/include
- you have to fix it to full path;{your-haxelib-repo}/hxcpp/{version}/include
- {here-yours};/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
- 'C ++语言方言'=
GNU ++ 11 [-std = gnu ++ 11]
- 'C ++标准库'=
libstdc ++(GNU C ++标准库)
- 'C++ Language Dialect' =
GNU++11 [-std=gnu++11]
- 'C++ Standard Library' =
libstdc++ (GNU C++ standard library)
-
^ h xModule.a
HxModule.a
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项目:
Additionally for autocomplete and better navigation you can add into Xcode-project the reference groups from directories:
-
include
来自Haxe的输出; -
包括
来自haxelibhxcpp
。
include
from output of Haxe;include
from haxelibhxcpp
.
在撰写本文时,只有一个可能的问题。可以通过编辑文件 {haxelib:hxcpp} /include/hxcpp.h
来解决。只需在文件开头添加几行:
At the time when this text was written only one possible issue. It can be solved by editing the file {haxelib:hxcpp}/include/hxcpp.h
. Simply add a few lines at the beginning of the file:
#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; }
...
在之后查看//标准标题....
。
。
这篇关于如何创建iOS-&来自Haxe的OSX-库并在本机应用程序中使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!