Forum Visual Studio

VS4Mac / Xamarin.Mac And C++ shared library

MikolajDawidowskiMikolajDawidowski USMember
edited May 2017 in Visual Studio

I am trying using C++ library (.a) in Visual Studio for Mac (a.k.a. Xamarin) I've found online some info on linking native libraries in Xamarin ( but it seems outdated since Visual Studio for Mac is out.

I uploaded both projects to

  1. MyCppLib - XCode project producing libMyCppLib.a
  2. XamarinMacApp - Visual Studio For Mac solution
  3. libMyCppLib.a - that is a product of MyCppLib, XamarinMacApp references it.

What is ok

MyCppLib compiles fine and produces libMyCppLib.a I intended to export only two C functions (my_C_Function, my_second_C_Function - MyCppLib.cpp) but I am unable to strip other sybols - which seems to be root of the problem

extern "C" {
        int my_C_Function();
        int my_second_C_Function();

In XamarinMacApp libMyCppLib.a is referenced (added to solution). And my_C_Function is called in AppDelegate.cs as follows:

using System.Runtime.InteropServices;
namespace XamarinMacApp
    public class AppDelegate : NSApplicationDelegate {

        public AppDelegate(){}

        static extern int my_C_Function();
        public override void DidFinishLaunching(NSNotification notification)
            int myretval = my_C_Function();

        public override void WillTerminate(NSNotification notification)
            // Insert code here to tear down your application

What's not ok XamarinMacApp - does not compile.

Notice that C functions (my_C_Function, my_second_C_Function is not listed in error below). It seems only C++ Standard Library cannot be linked.

Full Visual Studio Mac compiler log. - link
Full Xcode compiler log: link

Here is an excerpt of the compiler output:

 "std::terminate()", referenced from:
      l008 in libMyCppLib.a(libMyCppLib.a-x86_64-master.o)
  "operator delete(void*)", referenced from:
      l001 in libMyCppLib.a(libMyCppLib.a-x86_64-master.o)
  "operator new(unsigned long)", referenced from:
      l001 in libMyCppLib.a(libMyCppLib.a-x86_64-master.o)
  "___cxa_begin_catch", referenced from:
      l005 in libMyCppLib.a(libMyCppLib.a-x86_64-master.o)
      l008 in libMyCppLib.a(libMyCppLib.a-x86_64-master.o)

Any ideas how to go forward?


Sign In or Register to comment.