How to create a static library of C/C++ for Xamarin projects targeting Tizen, Android, and iOS

Original Created May 10, 2020 | Regeneration Apr 22, 2026

We have our own C/C++ libraries for our application and want to port it to the .NET platform. Our targets include Tizen, Android, and iOS. Please guide us on how to build the static library for C/C++.

Problem Understanding

The user wants to create a static library from existing C/C++ code that can be used in Xamarin projects targeting multiple platforms including Tizen, Android, and iOS.

Solution Methods

  1. Creating the Shared Library in Tizen Studio

    • Open Tizen Studio and select File > New > Tizen Project > Template
    • Select Target device and Tizen version (e.g., Wearable 4.0 for Galaxy Watch)
    • Choose Native App > Shared Library
    • Set the target architecture in Project Explorer by right-clicking your project and selecting Properties
    • In Properties window, go to C/C++ Build > Tizen Settings and select arm in Platform > Architecture drop-down list
    • Click Apply and Close
  2. Integrating with Xamarin.Tizen Project

    • After building your code, copy the output .so file to your C# project's lib directory
    • Use P/Invoke (DllImport) to call the native functions
  3. Sample Implementation

    • Create a header file with exported functions using EXPORT_API macro
    • Implement the functions in a C/C++ source file
    • Build the library in Tizen Studio
    • Copy the .so file to your Xamarin.Tizen project's lib directory
    • Use DllImport in C# to call the native functions

Code Examples

Native Library Header (mytizensharedlibrary.h):

#ifndef _MYTIZENSHAREDLIBRARY_H_
#define _MYTIZENSHAREDLIBRARY_H_

#include <stdbool.h>
#include <tizen.h>

#ifdef __cplusplus
extern "C" {
#endif

EXPORT_API void tizenmytizensharedlibrary(int num);

#ifdef __cplusplus
}
#endif
#endif // _MYTIZENSHAREDLIBRARY_H_

Native Library Implementation (mytizensharedlibrary.c):

#include "mytizensharedlibrary.h"
#include <stdio.h>

void tizenmytizensharedlibrary(int num) {
    printf("Hi Tizen! num(%d)\n", num);
}

Xamarin.Tizen Project File (.csproj):

<Project Sdk="Tizen.NET.Sdk/1.0.9">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>tizen40</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <Folder Include="lib\" />
    <Folder Include="res\" />
  </ItemGroup>
</Project>

C# Code to Call Native Function:

[DllImport("libmytizensharedlibrary.so", EntryPoint = "tizenmytizensharedlibrary")]
internal static extern void CallMyLibrary(int num);

protected override void OnCreate() {
    base.OnCreate();
    LoadApplication(new App());
    CallMyLibrary(2020);
}

Additional Tips

  • Ensure the .so file is copied to the correct location in your Xamarin.Tizen project
  • Verify the architecture settings match your target device
  • For Android integration, use AndroidNativeLibrary in the csproj file
  • If issues persist, create a simple sample app to reproduce the problem

Customize your cookie preferences

You can enable or disable non-essential cookies. Essential cookies are always on to ensure the site works properly and to keep you signed in.

Necessary

These cookies are necessary for the website to function properly and cannot be switched off. They help with things like logging in and setting your privacy preferences.

Always on

Analytics

These cookies help us improve the site by tracking which pages are most popular and how visitors move around the site.

Enable analytics cookies
Public Forum Public Forum
Employees only. Please sign in with your company account.