Giter VIP home page Giter VIP logo

xamarin-pinvoke-example's Introduction

Xamarin-PInvoke-Example

This repository demonstrates using PInvoke in Xamarin C# to call methods in an XCode C++ class.

To use this project you need to build the C and C++ from the command line using "make". To clean the build use "make clean"

After the make has completed you will have a libPInvokeTestSDK.a file which is the static library that is needed in the Xamarin project.

libPInvokeTestSDK.a is built to contain all the required architectures. Run lipo to examine the contents: lipo -info libPinvokeTestSDK.a Architectures in the fat file: libPinvokeTestSDK.a are: i386 armv7 x86_64 arm64

Every time you make a change to your XCode project you will need to copy a new fat library from the XCode project intot he Xamarin project.

Linker options are set to generate a map file (output.map) so you can see the symbols.

Behind the scenes:

The Build Options in the Xamarin project (Build > iOS Build > Additional Options) need to be configured: -cxx -gcc_flags "-L${ProjectDir} -lPinvokeTestSDK -force_load ${ProjectDir}/libPinvokeTestSDK.a" -gcc_flags "-Wl,-map,${ProjectDir}/output.map"

The XCode Project's Code Signing is set to Developer.

Known Issues

  1. BUIlding the sample app fails in Visual Studio because the libPInvokeTestSDK.a is not copied to the build server. To fix this, you need to set the "Copy to output directory" value in the libPInvokeTestSDK.a properties to "Copy Always". It is currently set to "Do not copy" which results in the library not being copied to the Mac build host and thus the file not being found. To fix this all you have to do is: a. Open the properties for the libPInvokeTestSDK.a and change the value for the "Copy to output directory" field to "Copy Always." b. Right click on the libPInvokeTestSDK.a file and select "Properties" c. In the properties pane that opens, change the value for "Copy to output directory" from "Do not copy" to "Always Copy".

xamarin-pinvoke-example's People

Contributors

bryonbaker avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.