Recent

Author Topic: [SOLVED] iOS Simulator: App with FPC dylib crashes  (Read 10643 times)

tk

  • Sr. Member
  • ****
  • Posts: 361
[SOLVED] iOS Simulator: App with FPC dylib crashes
« on: December 06, 2016, 06:27:33 pm »
Hi, this problem corresponds with
http://forum.lazarus.freepascal.org/index.php/topic,34431.0.html
and
http://forum.lazarus.freepascal.org/index.php/topic,32789.0.html
.

I try to add my custom dylib to local embedded framework in a Xamarin application.

I already have my dylib compiled and lipoed for all 4 targets (darwin-arm,aarch64 + iphonesim-i386,x86_64).

And I have this demo application for Xamarin:
https://github.com/rolfbjarne/embedded-frameworks
solution simpleapp-with-nativereferences.sln.

Open the solution in Xamarin and replace the MyFramework dylib from this demo (compiled with objective C compiler) with my dylib compiled with FPC.

Then I build Xamarin app for iOS target 8.0 and run iPhone 6 simulator on my virtual OSX (iOS 8 is required for embedded frameworks).
The app crashes immediately and following crash report is created:

Code: [Select]
...
Dyld Error Message:
  Library not loaded: /Volumes/*/mylibrary
  Referenced from: /Users/USER/Library/Developer/CoreSimulator/Devices/6B03A753-BC7D-49F2-A607-DFD5085602A0/data/Containers/Bundle/Application/99C2E843-42AC-4664-8ECA-53B5FA0C8AF4/simpleframeworktest.app/simpleframeworktest
  Reason: no suitable image found.  Did find:
/Volumes/*/mylibrary: missing LC_DYLD_INFO load command
...

What could be the reason?

Versions:
On MAC:
OSX 10.11 El Capitan
FPC 3.1.1 from trunk, crossinstalls compiled from this for all 4 iOS targets
Lazarus 1.7 from trunk
Xamarin 6.1.2
XCode 7.3.1

On Win:
Win7x64
VS 2015
Xamarin iOS 10.2

Thank you
« Last Edit: December 06, 2016, 10:18:13 pm by tk »

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1058
Re: iOS Simulator: App with FPC dylib crashes
« Reply #1 on: December 06, 2016, 06:33:18 pm »
Try specifying the targeted iOS/iPhoneSim version when compiling the library with FPC using its -WP parameter. If nothing is specified, FPC 3.0.x tells the linker to create a binary for iOS/iPhoneSim 7.0

tk

  • Sr. Member
  • ****
  • Posts: 361
Re: iOS Simulator: App with FPC dylib crashes
« Reply #2 on: December 06, 2016, 08:08:37 pm »
Thank you Jonas. The -WP8.0 definitely helped, ie. put me further. But the crash persists, now with:

Code: [Select]
Dyld Error Message:
  Library not loaded: /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
  Referenced from: /Volumes/*/mylibrary
  Reason: no suitable image found.  Did find:
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation: mach-o, but not built for iOS simulator

Isn't the problem that I use WideString in the library code that possibly links fpc\packages\iosxlocale\src\iosxwstr.pp ? There I can see {$linkframework CoreFoundation} and maybe there is the problem that it takes OSX stuff instead of iOS stuff?
« Last Edit: December 06, 2016, 09:07:10 pm by tk »

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1058
Re: iOS Simulator: App with FPC dylib crashes
« Reply #3 on: December 06, 2016, 10:10:00 pm »
Well, do you tell the compiler/linker to link against the appropriate iphonesim SDK via the -XR parameter?

tk

  • Sr. Member
  • ****
  • Posts: 361
Re: iOS Simulator: App with FPC dylib crashes
« Reply #4 on: December 06, 2016, 10:14:41 pm »
Well, do you tell the compiler/linker to link against the appropriate iphonesim SDK via the -XR parameter?

No! I had paths for arm targets but not for the simulator targets!
In the meantime found solution myself.

Edit fpc.cfg, and add eg.:

Code: [Select]
#cross compile settings dependent on both target OS and target CPU
#IFDEF FPC_CROSSCOMPILING

#IFDEF DARWIN
#IFDEF CPUARM
-ap
#ENDIF
-XR/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/
-FD/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/
#ENDIF

#IFDEF IPHONESIM
-XR/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/
-FD/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/
#ENDIF

#ENDIF


Marking this solved. Thank you Jonas, great help.

PS. Didn't test yet on real device, so hopefully settings for them are correct.
« Last Edit: December 06, 2016, 10:17:48 pm by tk »

 

TinyPortal © 2005-2018