Are there any CSharp examples using

I’m using Xamarin on Android, and I’m trying to get c# interop to correctly register the callback to zts_start in the shared object library.
I found the zt.i command that is being used by swig, but it fails to find two files specified.

%module libzt
#include "../include/ZeroTier.h"
#include "../include/ZeroTierConstants.h"

I’m trying to call zts_start:

        _callback = new CSharpCallback(MyCallback);
        var currentDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
        err = zts_start(currentDirectory, _callback, 9993);

zts_start always returns -3, which seems to point to the callback being in an incorrect format.

    [DllImport("zt", CallingConvention = CallingConvention.Cdecl)]
    public static extern int zts_start(string path,  [MarshalAs(UnmanagedType.FunctionPtr)]CSharpCallback callback, UInt16 port);

    private CSharpCallback _callback;


Luckily we’ve been putting some work into this lately. Check out:

It’s still a work in progress and will be updated heavily over the course of the next week but it does work (you may need to tweak the Makefile for your environment). Let me know if you have any questions.

Must be my lucky day. Thanks for your work on this.

Ubuntu 20.04
On > make all
I kept getting
error: ‘uint32_t’ does not name a type; did you mean ‘u_int32_t’.
That cleared up when I did a pull. THANK YOU.

Now it’s saying,
/usr/bin/ld: lib/libzt.a(Controls.cpp.o): in function zts_start': Controls.cpp:(.text+0x2ed): undefined reference to pthread_create’
/usr/bin/ld: Controls.cpp:(.text+0x305): undefined reference to pthread_create' /usr/bin/ld: Controls.cpp:(.text+0x31c): undefined reference to pthread_setname_np’

What toolchain should I be using to build libzt. I’ve tried different combinations of clang and gcc on Mac and Linux. I can get it to build with mild code changes, but I’m thinking it should build without those.

On Mac, I get
Check dependencies
zt will not be code signed because its settings don’t specify a development team.
error: unable to read module map contents from ‘/users/jhammer/libzt/ports/module.modulemap’: Error Domain=NSCocoaErrorDomain Code=260 “The file “module.modulemap” couldn’t be opened because there is no such file.” UserInfo={NSFilePath=/users/jhammer/libzt/ports/module.modulemap, NSUnderlyingError=0x7fc390f34120 {Error Domain=NSPOSIXErrorDomain Code=2 “No such file or directory”}}
warning: no umbrella header found for target ‘zt’, module map will not be generated

make all really does do everything, including all the stuff you might not be equipped to build. I would suggest pulling latest and just using the make targets host_pinvoke, host_pinvoke_debug or host_pinvoke_release.

I’ve tested this on my Mac, and on Ubuntu Server 20.04 LTS running clang version 10.0.0-4ubuntu1

Let me know if that doesn’t clear things up.

Mostly there.

zts_start keeps returning -3 (ERR_ARG)

If I get this working, I’ll clean up a xamarin example and submit it.

One other thing that MAY be relevant.

I’m using OpenJDK. I updated gradle to get it to work.
Is Oracle’s JDK required?