HaxeFoundation / HaxeFoundation/haxe

[CPP+OBJC] Missing hx::__ObjcClass

Open
#6,127 1 comment 0 reactions 0 assignees View on GitHub
platform-cpp
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

I try to compile a static library for iOS/macOS with `-D objc` and using classes in the package `cpp.objc`. The library compiled fine. But when linking in Xcode project I got error:

```
Undefined symbols for architecture i386:
"hx::__ObjcClass", referenced from:
hx::ObjcData::__GetClass() const in hx.iphonesim.a(c2b7dbaa_ObjcData.o)
```

Haxe: `3.4.2` (release)
Hxcpp: `3.4.64` (release)
Xcode: 8.2.1 (8C1002)

## Steps to reproduce:
1. Compile haxe to static lib for iOS-sim;
1. Create iso-project in Xcode
1. Add link static lib (by haxe)
1. Try to build

### Unexpected result:

```
Undefined symbols for architecture i386:
"hx::__ObjcClass", referenced from:
hx::ObjcData::__GetClass() const in hx.iphonesim.a(c2b7dbaa_ObjcData.o)
```

## Haxe source

Hxml:
```hxml
-D objc
-D HXCPP_USE_LIBTOOL
-D STATIC_LINK
-D HXCPP_CPP11
-D OBJC_ARC

-dce no
# include classes:
bar.Foo

-D iphonesim
-cpp out/cpp-ios-sim
```

bar/Foo.hx:
```haxe
package bar;

import cpp.objc.*;

@:keep class Foo {
public static function test():Void {
trace("Hello!");
var fooo = {o:"", p:42, i:.0};
trace(fooo.o.length);

NSLog.log("that: - %@ -", fooo);
}
}
```

## Xcode project source

main.mm:
```objc++
#import
#import "AppDelegate.h"
#import "Foo.h"

int main(int argc, char * argv[])
{
HX_TOP_OF_STACK hx::Boot(); __boot_all();

@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
```

AppDelegate.mm:
```objc++
#import "AppDelegate.h"
#import "Foo.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
bar::Foo_obj::test();
return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {}
- (void)applicationDidEnterBackground:(UIApplication *)application {}
- (void)applicationWillEnterForeground:(UIApplication *)application {}
- (void)applicationDidBecomeActive:(UIApplication *)application {}
- (void)applicationWillTerminate:(UIApplication *)application {}
@end
```

## Workaround:

As a temporary solution I removed the `-D objc` and use of the package `cpp.objc` and everything works fine.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.