如何从Haxe创建iOS-和OSX-库并在本机应用程序中使用它?

前端之家收集整理的这篇文章主要介绍了如何从Haxe创建iOS-和OSX-库并在本机应用程序中使用它?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个在Haxe上编写自己的协议,数据结构和逻辑的跨平台实现.如何在iOS和OSX的企业应用程序(使用本机UI)中构建和使用它?

解决方法

如何从Haxe创建iOS- / OSX-库并在本机应用程序中使用它

Actuality: 12.2014; HXCPP-ver.: 3.1.39~git.

Dependency: 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-project< - Library
>创建一个新的Xcode项目.它可以用于OSX或iOS,应用程序或Cocoa Framework.
>在“项目”/“构建设置”/“标题搜索路径”中添加依赖项的路径:(所有路径必须是完整/非相对和递归)

> out / cpp / module / include – 你必须将它修复到完整路径;
> {your-haxelib-repo} / hxcpp / {version} / include – {here-yours};
> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include

>在“项目”/“构建设置”/“Apple LLVM 6.0 – 语言 – C”中更改值:

>’C语言方言’= GNU 11 [-std = gnu 11]
>’C标准库’= libstdc(GNU C标准库)

>在’Project’/’Build Phases’/’Link Binary With Libraries’中:

> HxModule.a

>重命名文件:AppDelegate.m – > AppDelegate.mm
>编辑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参考组:

>包括Haxe的输出;
>包括来自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; }
...

看看//标准标题…..

Example project.

原文链接:https://www.f2er.com/iOS/327883.html

猜你在找的iOS相关文章