Xamarin Studio linking static libs problem - iOS

Hi, all.

I have framework which is written in C++ which I would like to use it in my Xamarin iOS application.

  1. I have compiled my C++ framework for a simulator and a device and created universal static libraries (e.g. libCPlusPlus1.a, libCPlusPlus2.a libCPlusPlus3.a and etc.)
  2. I have wrapped by SWIG my C++ code to C# code
  3. Then have compiled my wrapped C# code for a simulator and a device and created a universal static library (e.g. libCSharpWrap.a)
  4. Then I have created an iOS Classic Library Project in Xamarin Studio and added all wrapped C# files into created project
  5. Next I have created iOS Single View Project and added all static libraries(libCSharpWrap.a, libCPlusPlus1.a, libCPlusPlus2.a ...) into created project
  6. In Single View Project created Reference to the iOS Classic Library project
  7. In the next step I have linked all my libraries - "-cxx -gcc_flags "-L${ProjectDir} -lCSharpWrap -force_load ${ProjectDir}/libCSharpWrap.a -lCPlusPlus1 -force_load ${ProjectDir}/libCPlusPlus1.a-lCPlusPlus2 -force_load ${ProjectDir}/libCPlusPlus2.a ... "
  8. And finally I have called my C# wrap code in Single View Project
  9. Build the solution and ...

As a result - linking is failed with any errors except of these useless errors:
MTOUCH: error MT5201: Native linking failed. Please review the build log and the user flags provided to gcc: ........
MTOUCH: error MT5202: Native linking failed. Please review the build log.

I beat my brains out trying to solve the problem. Finally in despiration I have commented my C# wrap code. And all libraries were linked!!!

Then I have uncommented my C# wrap code and built the application again. All libraries were linked, the application was built succesfully and launched.

But now every time when I call "Clean" I have to remove or comment my C# wrap code in order to link libraries. Then I have to add or uncomment my C# code and build it again.

What I am doing wrong? Please, help. Can it be a bug of Xamarin Studio?

Best Answers

Answers

  • No answers, OK, let me describe my problem in a nutshell.

    I have C++ Framework which I have wrapped by SWIG to C# code. I have linked all my C++ static libraries and wrapped C# static library.

    I can Build and Run my application on simulator until I call "Clean all". If I call "Clean all" and then "Build all" I got linking errors MTOUCH: error MT5202: Native linking failed. Please review the build log.

    In order to resolve this linking errors I remove all my C# wrap code then call "Build all" again. After that I add my C# code.

    Additionally I can't Run my application on device at all, I got linking errors always.

    Please, help.

  • DenisGordinDenisGordin RUMember ✭✭
    Accepted Answer

    Did you see that article? https://developer.xamarin.com/guides/ios/advanced_topics/linker/.
    I'm pretty sure you can find answer there.
    I don't have any issue like this, but maybe you should add [Preserve] attribute for the wrapped library, for example.

Sign In or Register to comment.