locked
Problems linking native library with Xamarin.iOS 7.2.1.42 RRS feed

  • Question

  • User4765 posted

    I updated to Xamarin.iOS 7.2.1.42 today and I am now getting lots of MT5210 (Native linking failed, undefined symbol) errors with my native C++ library. I have read the notes here and have tried to use the legacy registrar settings, but without any luck...

    Here are my additional mtouch arguments (for Simulator) that worked before updating to 7.2.1.42:

    -cxx -gcc_flags "-L${SolutionDir}/${ProjectDir}/libs/ -lmylibrary -force_load ${SolutionDir}/${ProjectDir}/libs/libmylibrary.a" --registrar:dynamic

    And I've tried changing them to:

    -cxx -gcc_flags "-L${SolutionDir}/${ProjectDir}/libs/ -lmylibrary -force_load ${SolutionDir}/${ProjectDir}/libs/libmylibrary.a" --registrar:olddynamic

    and

    -cxx -gcc_flags "-L${SolutionDir}/${ProjectDir}/libs/ -lmylibrary -force_load ${SolutionDir}/${ProjectDir}/libs/libmylibrary.a" --registrar:legacy

    without any luck.

    Additionally, I've tried wrapping this library in a binding project and I get the same errors.

    Any ideas?

    Thursday, May 1, 2014 7:15 PM

All replies

  • User2589 posted

    Can you post (e.g. a link to a gist) your full build log ? It might not be related to the registrar but, without more details, it's hard to guess what could be wrong.

    Thursday, May 1, 2014 8:18 PM
  • User4765 posted

    @SebastienPouliot? Understood. Here is the build log before changing the registrar settings...as changing them gives the same errors: http://pastebin.com/tUTcRaL6

    Thursday, May 1, 2014 8:25 PM
  • User2589 posted

    The openNURBS library looks to be C++ so I do not think it's related to the registrar.

    Now it's uncommon to use Release on the iOS Simulator. Are you sure you could not have switched from Debug to Release configuration ?

    It's often easy to forget to update the Release configuration when modifying the Debug options (e.g. when adding additional mtouch arguments).

    What happens on Debug or when you build for devices ?

    Thursday, May 1, 2014 8:45 PM
  • User4765 posted

    @SebastienPouliot? That build log is from a Debug configuration. Building for Debug on devices yields the same results.

    Here are my additional mtouch arguments for Release | Device:

    -cxx -gcc_flags "-L${SolutionDir}/RV.Touch/libs/ -lopennurbs -force_load ${SolutionDir}/RV.Touch/libs/libopennurbs.a"

    This has been working without issue until the update to 7.2.1.42 today.

    Thursday, May 1, 2014 8:51 PM
  • User2589 posted

    Oops my bad. There was a lot of Release in the paths of the logs (but unrelated) but the build itself is from the Debug configuration.

    Could you try to build a small test case (e.g. that use the library, but without the rest of your application) and attach that to a bug report ?

    Also were you using 7.2.0 or something older because updating ? or did you update other things (e.g. Xcode) ?

    Thursday, May 1, 2014 9:04 PM
  • User4765 posted

    @SebastienPouliot? No worries. Yeah, there's a lot of Release going on there.

    Yes, I can put together a bug report with a test case.

    As far as I remember, before updating, I was using whatever previous version of Xamarin.iOS was in the stable channel. Yes, I updated Xcode to 5.1.1, but that was days ago.

    Thursday, May 1, 2014 9:11 PM
  • User4765 posted

    @SebastienPouliot?

    Bug submitted

    Sincerely hoping this is an easy fix (or something small that I'm doing wrong) as the entire projects depends on this library.

    Thanks again for looking into it.

    Thursday, May 1, 2014 10:56 PM
  • User1365 posted

    I can no longer debug on a device either!

    error MT5211: Native linking failed, 
    error MT5210: Native linking failed,
    error MT5202: Native linking failed,
    

    It was fine before the last Xamarin update.

    Friday, May 2, 2014 2:41 PM
  • User7149 posted

    Me too, same problems.

    Friday, May 2, 2014 5:17 PM
  • User4765 posted

    Anyone know an quick way to rollback from 7.2.1 to 7.2.0?

    Friday, May 2, 2014 11:56 PM
  • User138 posted

    @DanBelcher? if you go to Xamarin.com, log into your account, select Downloads and you can pick prior releases to download and install.

    Friday, May 2, 2014 11:59 PM
  • User263 posted

    Having problems with 7.2.1 also, native linking fails for ShinobiEssentials and ShinobiGrid components available on the Xamarin component store.

    Reverting to 7.2 - not cool when a minor dot release like this breaks a considerable amount of functionality, especially 3rd party components available on the component store.

    Monday, May 5, 2014 1:50 AM
  • User44952 posted

    I'm also getting an error after updating to 7.2.1. I can't run my project on iOS simulator and the app crashes. Here is the error:

    Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Unable to instantiate the UIApplication delegate instance. No class named [Project Name].Touch.AppDelegate is loaded.

    Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Unable to instantiate the UIApplication delegate instance. No class named [Project Name].Touch.AppDelegate is loaded. at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr) at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38 at Sanofi.Hector.Touch.Application.Main (System.String[] args) [0x0000e] in [Project Name].Touch/Main.cs:19

    Monday, May 5, 2014 7:36 AM
  • User39 posted

    @EhsanSemsar: are any other exception messages shown in the Application Output at startup?

    Monday, May 5, 2014 2:29 PM
  • User44952 posted

    I think I found the problem. The latest version of Xamarin.ios SDK for Mac Os is not compatable with the latest version of Xamarin.ios SDK for Windows. I use visual studio and when I downgrade the SDK it for Mac OS it works fine.

    Tuesday, May 6, 2014 1:10 AM
  • User13824 posted

    For folks seeing these errors with the upgrade to 7.2.1, be sure to read through the documentation about the new registrar to see if it might apply:

    • http://docs.xamarin.com/guides/ios/advanced_topics/registrar/

    Two particularly common forms of errors with the new registrar are:

    1. Error MT5210: Native linking failed, undefined symbol: _foo. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in. (MT5210)

    2. Error MT5211: Native linking failed, undefined Objective-C class: _OBJC_CLASS_$_MyDelegate. If '_OBJC_CLASS_$_MyDelegate' is a protocol from a third-party binding, please check that it has the [Protocol] attribute in its api definition file, otherwise verify that all the necessary frameworks have been referenced and native libraries are properly linked in. (MT5211)

    Workarounds, fixes

    1. As mentioned on the bug report from earlier, there are a few ways to work around this problem:

      • Remove the P/Invokes in question from your source code. This is "correct" fix.
      • Enable the managed linker for all assemblies (this is done in the project's iOS Build options, by setting "Linker Behavior" to "All assemblies"). This will effectively remove all the P/Invokes you don't use from the app (automatically, instead of manually like the previous point). The downside is that this will make your simulator builds somewhat slower, and it may break your app if it's using reflection - more information about the linker can be found here: http://docs.xamarin.com/guides/ios/advanced_topics/linker/)
      • Create a second native library which contains the missing native symbols. Note that this is merely a workaround (if you happen to try to call those functions, your app will crash). For example, you can define variables for the missing names:

        void *foo = 0;  
        

        ... and then compile the file into a new native library:

        clang -arch i386 -arch x86_64 -arch armv7 -arch armv7s -arch arm64 -c mydefs.c -o mydefs.o
        
    2. As mentioned in the release notes, you can work around this problem temporarily by adding --registrar:legacy to "Project Options -> iOS Build -> Additional mtouch arguments".

      To fix the problem, you'll need to add the [Protocol] attribute (as requested by the error message), and then recompile the binding library. If you don't have access to the source for the binding library, the author of the library will have to perform this step.

    Tuesday, May 6, 2014 2:19 PM
  • User351573 posted

    @EhsanSemsar said: I think I found the problem. The latest version of Xamarin.ios SDK for Mac Os is not compatible with the latest version of Xamarin.ios SDK for Windows. I use visual studio and when I downgrade the SDK it for Mac OS it works fine.

    I am also getting the same exception: Foundation.MonoTouchException has been thrown Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Unable to instantiate the UIApplication delegate instance. No class named AppDelegate is loaded. Screenshot: I didn't understand the solution you prefer, I am using visual studio(in mac) for the development, can you help me to solve this issue? Thanks in advance :)

    Friday, February 16, 2018 7:01 AM
  • User351573 posted

    @EhsanSemsar said: I think I found the problem. The latest version of Xamarin.ios SDK for Mac Os is not compatable with the latest version of Xamarin.ios SDK for Windows. I use visual studio and when I downgrade the SDK it for Mac OS it works fine.

    I am using visual studio 2017 community in mac and using xcode 9.2(latest version)

    Friday, February 16, 2018 7:31 AM
  • User351573 posted

    @EhsanSemsar said: I'm also getting an error after updating to 7.2.1. I can't run my project on iOS simulator and the app crashes. Here is the error:

    Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Unable to instantiate the UIApplication delegate instance. No class named [Project Name].Touch.AppDelegate is loaded.

    Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Unable to instantiate the UIApplication delegate instance. No class named [Project Name].Touch.AppDelegate is loaded. at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr) at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38 at Sanofi.Hector.Touch.Application.Main (System.String[] args) [0x0000e] in [Project Name].Touch/Main.cs:19

    Solve this issue by setting the Build Action property of AppDelegate.cs to Combile :) It is a trap for young players :)

    Saturday, February 17, 2018 9:47 AM
  • User349199 posted

    hi All, i have made a binding library, But it's not working in my application and giving me error like as: MTOUCH : error MT5211: Native linking failed, undefined Objective-C class and i have tried to add Protocol attribute on it , after that my code is build successfully but getting an exception when calling the methods and exception ios 'Foundation.ModelNotImplementedException'. i am facing this from long time but not getting any solution So, Please help me with this issue.

    Thank You

    Friday, March 16, 2018 2:34 PM
  • User349199 posted

    @Sreeee Solve this issue by setting the Build Action property of AppDelegate.cs to Combile :) It is a trap for young players :)

    How it could be done on AppDelegate.cs file. cause i am new in Xamarin , So, i don't understand "Build Action property of AppDelegate.cs to Combile"

    Friday, March 16, 2018 2:37 PM
  • User351573 posted

    Hi @Tusshar

    Right click on the AppDelegate.cs file in the solution explorer and select properties option, and set the Build Action property to Combile

    Saturday, March 17, 2018 6:08 AM