How to create an iOS and OSX library from Haxe and use it in your own application?

I have a cross-platform implementation of my own protocol, data structures and logic written in Haxe. How can I create and use it in my corporate application (with my own user interface) for iOS and OSX?

+6
source share
1 answer

How to create an iOS / OSX library from Haxe and use it in your own application

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

Dependency: hxcpp

1. Haxe → Library

Create a new Haxe project with a main class named HxModule .

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

  • Create a new Xcode project. It can be for OSX or iOS, Application or Cocoa Framework.
  • In the "Project" / "Build Setting" / "Header Search Paths" settings add the paths to the dependencies: (all paths must be full / non-relative and recursive )
    • out/cpp/module/include - you need to fix it to the full path;
    • {your-haxelib-repo}/hxcpp/{version}/include - {here-yours};
    • /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
  • In the settings "Project" / "Build Settings" / "Apple LLVM 6.0 - Language - C ++":
    • 'C ++ language dialect' = GNU++11 [-std=gnu++11]
    • 'C ++ Standard Library' = libstdc++ (GNU C++ standard library)
  • In 'Project' / 'Build Phases' / 'Link Binary With Libraries':
    • HxModule.a
  • Rename file: AppDelegate.mAppDelegate.mm
  • Edit AppDelegate.mm :
Appdelegate.mm
 #import "AppDelegate.h" #import "HxModule.h" @implementation AppDelegate - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { NSLog(@"test: %d", ((int)HxModule_obj::test())); } @end 

Additionally, for autocompletion and better navigation, you can add reference groups from directories to the Xcode project:

  • include from Haxe output;
  • include from haxelib hxcpp .
Possible problems:

At a time when only one possible problem was written in this text. It can be solved by editing the file {haxelib:hxcpp}/include/hxcpp.h . Just add a few lines at the beginning of the file:

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

see after // Standard headers ....

Sample project .

+8
source

Source: https://habr.com/ru/post/979244/


All Articles