hajimehoshi / ebiten

Ebitengine - A dead simple 2D game engine for Go
https://ebitengine.org
Apache License 2.0
11.05k stars 662 forks source link

cmd/ebitenmobile: building an iOS App results in error messages #2196

Open staatzstreich opened 2 years ago

staatzstreich commented 2 years ago

Using Mac Monterey 12.4 and Xcode Version 13.4.1 (13F100):

1.) started a new Project => iOS => App => Storyboard + Objective-C 2.) Added the "your game.xcframework" with drag and drop to the project (Check "Copy items if needed" at the dialog box that appear) 3.) Modified the ViewController.h to:

#import <UIKit/UIKit.h>
#import "Patience/MobileEbitenViewController.h"

@interface ViewController : MobileEbitenViewController

@end 

4.) and the ViewController.m is unedited:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

@end

At Storyboard the ViewController has "Is Initial View Controller" checked at the Attributes Inspector, as the documentation say's.

Building the project for the Simulator resulted in following error messages:

Ld /Users/username/Library/Developer/Xcode/DerivedData/Patience-aipwjfbqxltvpuedwjchmqviovus/Build/Products/Debug-iphonesimulator/Patience.app/Patience normal (in target 'Patience' from project 'Patience')
    cd /Users/username/CodeProjects/patience-max/mobile/ios/Patience
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -target x86_64-apple-ios15.5-simulator -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.5.sdk -L/Users/username/Library/Developer/Xcode/DerivedData/Patience-aipwjfbqxltvpuedwjchmqviovus/Build/Products/Debug-iphonesimulator -F/Users/username/Library/Developer/Xcode/DerivedData/Patience-aipwjfbqxltvpuedwjchmqviovus/Build/Products/Debug-iphonesimulator -filelist /Users/username/Library/Developer/Xcode/DerivedData/Patience-aipwjfbqxltvpuedwjchmqviovus/Build/Intermediates.noindex/Patience.build/Debug-iphonesimulator/Patience.build/Objects-normal/x86_64/Patience.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -dead_strip -Xlinker -object_path_lto -Xlinker /Users/username/Library/Developer/Xcode/DerivedData/Patience-aipwjfbqxltvpuedwjchmqviovus/Build/Intermediates.noindex/Patience.build/Debug-iphonesimulator/Patience.build/Objects-normal/x86_64/Patience_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -Xlinker -objc_abi_version -Xlinker 2 -fobjc-arc -fobjc-link-runtime -Xlinker -sectcreate -Xlinker __TEXT -Xlinker __entitlements -Xlinker /Users/username/Library/Developer/Xcode/DerivedData/Patience-aipwjfbqxltvpuedwjchmqviovus/Build/Intermediates.noindex/Patience.build/Debug-iphonesimulator/Patience.build/Patience.app-Simulated.xcent -framework Patience -Xlinker -no_adhoc_codesign -Xlinker -dependency_info -Xlinker /Users/username/Library/Developer/Xcode/DerivedData/Patience-aipwjfbqxltvpuedwjchmqviovus/Build/Intermediates.noindex/Patience.build/Debug-iphonesimulator/Patience.build/Objects-normal/x86_64/Patience_dependency_info.dat -o /Users/michaelstaatz/Library/Developer/Xcode/DerivedData/Patience-aipwjfbqxltvpuedwjchmqviovus/Build/Products/Debug-iphonesimulator/Patience.app/Patience

Undefined symbols for architecture x86_64:
  "_GCControllerDidConnectNotification", referenced from:
      _initializeGamepads in Patience(000039.o)
  "_GCControllerDidDisconnectNotification", referenced from:
      _initializeGamepads in Patience(000039.o)
  "_GCInputDualShockTouchpadButton", referenced from:
      _getControllerState in Patience(000039.o)
      _getControllerPropertyFromController in Patience(000039.o)
  "_GCInputXboxPaddleOne", referenced from:
      _getControllerState in Patience(000039.o)
      _getControllerPropertyFromController in Patience(000039.o)
  "_GCInputXboxPaddleTwo", referenced from:
      _getControllerState in Patience(000039.o)
      _getControllerPropertyFromController in Patience(000039.o)
  "_GCInputXboxPaddleThree", referenced from:
      _getControllerState in Patience(000039.o)
      _getControllerPropertyFromController in Patience(000039.o)
  "_OBJC_CLASS_$_GCController", referenced from:
      objc-class-ref in Patience(000039.o)
  "_GCInputXboxPaddleFour", referenced from:
      _getControllerState in Patience(000039.o)
      _getControllerPropertyFromController in Patience(000039.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

best, Michael

hajimehoshi commented 2 years ago

Does your project include GameController.framework in the dependency list?

image

staatzstreich commented 2 years ago

Hi,

i had GameController.framework already included... and I can build the project. After reading your answer I also include what you suggest... Have no luck with "running" the app ... it build, start simulator but after a few seconds it stops with a "Thread 1: EXC_BAD_ACCESS (code=1, address=0x48)" at "UIApplicationMain" in "main.m"... same as with only GameController.framework included...

hajimehoshi commented 2 years ago

Hmm, I couldn't reproduce your issue unfortunately. I think the error says the linker misses GameController.framework.

staatzstreich commented 2 years ago

As I said... I could build the project without any error, but running the app with the simulator ended with => "Thread 1: EXC_BAD_ACCESS (code=1, address=0x48)" at "UIApplicationMain" in "main.m"...

That is out of my experience.... I think i will learn more game programming with Mac and WebAssembly first .... thanks for helping out :)

hajimehoshi commented 2 years ago

OK so now the building succeeds and you see EXC_BAD_ACCESS. However, I couldn't reproduce this either.

What about actual devices instead of an emulator? And, can I see the error message's detail more?

staatzstreich commented 2 years ago

Started a fresh project, included all Frameworks that you mentioned, including mine. Added an iPad as device (now I have an free developer account :) ) building succeeds and then there is the same error but this time it is better to see what happens in the debugger:

Bildschirmfoto 2022-07-12 um 05 50 34

Here is the func:

Bildschirmfoto 2022-07-12 um 05 56 08

where "emptyPile" is global: var emptyPile *ebitenImage

With Webassembly this works fine on my iPad... you can try at => https://staatzstreich.de/patience2

i will investigate that....

staatzstreich commented 2 years ago

I have created a new project based on the runner example and with deeper investigation of the go-inovation example and at the end I have a project that run with simulator and my own device.

I will take this as a starting point for further coding.

Ticket can be closed. Thanks for pointing in the right direction.

briansunter commented 2 years ago

I had this exact same issue. Could not get it to work with a fresh xcode project, but worked fine by adapting the go-innovation repo.

I included all the frameworks, but hit the same cryptic error as above in the simulator.

Webasm worked fine for me as well.

hajimehoshi commented 2 years ago

I'll try a fresh project.

hajimehoshi commented 2 years ago

I created an empty Xcode project and succeeded to run with the go-inovation xcframework.

Also I simplified the instruction for iOS: https://ebitengine.org/en/documents/mobile.html#iOS

hajimehoshi commented 2 years ago

@briansunter Do you have more information about your issue? Stacktrace for example.