iosxamarinxamarin.macxamarin-linker

Linking stdlibs with Xamarin


I have created a simple binding project with Xamarin. The binding project imports a static library MyLibrary.a. It also contains ApiDefinition.cs and StructAndEnum.cs made through sharpie tool.

Now I have an iOS project that links that binding project. MyLibrary.a in order to work needs some frameworks and libs (see below).

enter image description here

In order to make it working, I followed the Xamarin documentation.

In the iOS project, I added the following mtouch arguments (see also attached imaged).

--cxx -gcc_flags "-L${ProjectDir} -framework CFNetwork -framework SystemConfiguration -framework MobileCoreServices -framework Security -framework AVFoundation -libicucore -libxml2 -libc++ -libzd -libstdc++.6.0.9"

enter image description here

When I try to compile I always end with a build error.

MTOUCH: error MT5209: Native linking error: library not found for -libicucore MTOUCH: error MT5201: Native linking failed. Please review the build log and the user flags provided to gcc: -L/Users/tmp/Documents/Projects/Ovp/BindinTest.iOS -framework CFNetwork -framework SystemConfiguration -framework MobileCoreServices -framework Security -framework AVFoundation -libicucore -libxml2 -libc++ -libzd -libstdc++.6.0.9 MTOUCH: error MT5202: Native linking failed. Please review the build log.

Any clue to make it work? Maybe something is missing?

Thank you in advance.


Solution

  • -libicucore -libxml2 -libc++ -libzd -libstdc++.6.0.9

    This is not how you pass library options for gcc linkage.

    To link a static or dynamic library libicucore.<extension> that resides in /path/to/the/lib, the commandline options are:

    -L/path/to/the/lib -licucore
    

    Note that the lib prefix of the library name is ommitted in the -l option: the linker assumes it. And if /path/to/the/lib is one of the linker's default search directories for libraries then you can omit it. If you have another look at your Xamarin documentation you will see that libMyLibrary.a is linked with the option -lMyLibrary.

    Some other things about these linkage options seem very odd to my GCC eyes, but as I know next to nothing about iOS development I won't anticipate problems that you haven't had yet.