Integrating C/C++ code in Xamarin for iOS - xamarin

Under Visual Studio 2015, I have integrated Android C++ code into Xamarin and it works as expected. Now, I am trying to do the same for iOS and am running into some basic issues.
I am assuming the integration mechanism is the same for iOS as that of Android in the sense that a shared library (probably .so) is created that one can load using DllImport in C# code.
When I try to add a new C++ project for iOS to my solution, the only option that seems to make sense is Visual C++-->Cross Platform-->iOS-->Shared Library. I added this project type as MyTestShared. This actually ends up creating three projects - MyTestShared.Shared, MyTestShared.iOS, and MyTestShared.Android. Project MyTestShared.iOS already has an external method defined as char* iOSInfo(). However, when I try to add project MyTestShared.iOS as a reference to my MyMainApp.iOS project, I see an error "A reference to MyTestShared.iOS could not be added. An assembly must have a dll or exe extension."
Questions:
For Android C++, it generates exactly one project. Why does it create three projects for iOS C++?
How do I add a reference to MyTestShared.iOS? What is it that I am missing?
I see there is an option to create a static C++ library for iOS. Can I reference it somehow in my C# code?
Regards.

Related

Mwarray.dll for Unity - How can I use it?

I have a problem with the MWArray.dll which is the original dll library from mathworks compiled from Matlab. This dll works under visual studio but not under unity. The goal was to compile under matlab a simple function mycos which calculates a cosinus and uses it under unity with the second dll MWArray mathworks library.
I made a test under Visual Studio and it works well. I have no problem to read the dll and make a call to the mycos.dll class. I made a typical c# project with two references on MWArray and mycos.
But when I try under unity, by putting the two dll under a plugins folder and configure unity 2018 on .NET 4.0 because the dll are compiled with the .NET framework 4.0.
Unity can read the dll but when running I get an error:
NotImplementedException: The requested feature is not implemented.
System.Security.Principal.WindowsIdentity.GetCurrent (Boolean ifImpersonating)
(at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Security.Principal/WindowsIdentity.cs:166)
If I want to use matlab for a research project which was coded in matlab with advanced high level math functions which going to be difficult to recode under unity with c#. So the easy way is to use compiled package from matlab compiler. So is there someone who did this already?
The solution consists in NOT using MWArray.dll in Unity project because of incompatibility with Mono. Create a Visual Studio project (when creating new select the type "console applicatiion"), it MUST be separated from unity project directory, and use it as an application server; in fact in that app you can use MWArray.dll, remember that you have to configure your project configuration to x64!!! In the Unity project create a client app to communicate with the other server project.

The target "GetBuiltProjectOutputRecursive" does not exist in the project when referencing netstandard library

I have a Xamarin Android project, and I am trying to add a reference to my own netstandard1.4 class library. When I add the reference, my Android application will no longer build. I get error MSB4057: The target "GetBuiltProjectOutputRecursive" does not exist in the project.
If I remove the reference, my android project builds fine.
The class library is a brand new library that I just created. It doesn't contain any actual code yet.
I am using Visual Studio 2017.
UPDATE: If I add a reference to my dll using the "Browse" function, it works. I only get the error when I add the reference to the project in my solution.
This appears to be fixed in 15.4

How to develop a xamarin forms component control to be used as dll in a project

I'm developing a xamarin forms class library (Custom Component) that targets (Windows, Androi and IOS) platforms "this library should be added to an existing Xamarin forms Portable project as DLL reference" and want to add a UI control and use it's native functions from inside the library. Custom renderers can't be added in PCLs so Can anyone help on how to access the control's native functionality?
You can start from scratch on your by following this piece of documentation by Xamarin on how to build NuGet packages. Then just make sure you build them without too much references and test them in your sample projects.
But to make your life a lot easier have a look at this Visual Studio extension by James Montemagno. It installs some project templates for you so naming is consistent and you have the basics already setup to start building your reusable code.

How do you reference a C++ dynamic Android library in Xamarin VS2015?

I created a Xamarin project MyApp within VS2015. This ends up creating a bunch of projects including MyApp.Droid for Android. I can build and deploy this project just fine on my Android device.
Next, I created a shared C++ Dynamic Shared Library (Android) project MyShared. When I try to add this project as a reference in MyApp.Droid, it reports an error that only .dll or .exe file types can be added as a reference and not .so types.
Wondering if there is a different way to add a native library project as a dependency. Regards.
Xamarin.Android supports the use of native libraries via the standard PInvoke mechanism.
You will need to define the DllImport C# attributes/signatures, there are various tools such as SWIG, PInvoker Visual Studio Addin, Mono's CppSharp, etc.. that can assist in this step.
(Personally I use Mono's CppSharp, but it might be overkill depending upon the number of classes/methods/functions there are within your C++ library.)
Mono Interop with Native Libraries
Xamarin.Android : Using Native Libraries
To interop with native libraries in your Xamarin.Android project, all you need to do is create a DllImport function declaration for the existing code to invoke, and the runtime will handle the rest. Set the EntryPoint to specify the exact function to be called in the native code.
Build and Debug C++ Libraries in Xamarin.Android Apps with Visual Studio 2015

Parse and Xamarin

I am using Xamarin and I was wondering if there is a way to run Parse in a shared project, so that I don't have to duplicate my code in the iOS project and the Android project in my solution?
Am I missing something, or do I really have to duplicate the Parse code?
What I did was create a Shared Project type to host my Parse specific Code. Then in my Xamarin.Android app, I reference the Parse.Android.dll. In my Xamarin.iOS code, I referenced the Parse.iOS.dll. Remember, that the "Shared Project" type does not create a DLL. Underneath the hood it's just file linking into your actual project, so it will use the references of that project. The Shared Project should not contain any iOS or Android specific code.

Resources