如何创建iOS-&来自Haxe的OSX-库并在本机应用程序中使用它? [英] How to create iOS- & OSX- library from Haxe and use it in native application?

查看:132
本文介绍了如何创建iOS-&来自Haxe的OSX-库并在本机应用程序中使用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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


现状:12.2014; HXCPP-ver。: 3.1.39 git

依赖关系: 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


  1. 创建一个新的Xcode项目。它可以用于OSX或iOS,Application或Cocoa Framework。

  2. 在'Project'/'Build Setting'/'Header Search Paths'中添加依赖项的路径:(所有路径必须是完整/不相对递归

  1. out / cpp / module / include - 您必须将其修复为完整路径;

  2. {your-haxelib-repo} / hxcpp / {version} / include - {here-yours};

  3. /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault .xctoolchain / usr / include

  1. out/cpp/module/include - you have to fix it to full path;
  2. {your-haxelib-repo}/hxcpp/{version}/include - {here-yours};
  3. /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include


  • 在'Project'/'Build Settings'/'Apple LLVM中6.0 - 语言 - C ++'更改值:

    • 'C ++语言方言'= GNU ++ 11 [-std = gnu ++ 11]

    • 'C ++标准库'= libstdc ++(GNU C ++标准库)

    • In the 'Project' / 'Build Settings' / 'Apple LLVM 6.0 - Language - C++' change values:
      • '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的输出;

        • 包括来自haxelib hxcpp

        • include from output of Haxe;
        • include from haxelib hxcpp.

        在撰写本文时,只有一个可能的问题。可以通过编辑文件 {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-&amp;来自Haxe的OSX-库并在本机应用程序中使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆