mono / CppSharp

Tools and libraries to glue C/C++ APIs to high-level languages
MIT License
3.1k stars 509 forks source link

Generating minimal unsafe bindings for pure C lib #989

Open raizam opened 6 years ago

raizam commented 6 years ago

I have a pure C library with structs and functions.

I just want to generate minimal bindings without any encapsulation and handle the higher level myself. I'm looking for this kind of layout:

internal static class ModuleName { [DllImport( CallingConvention = CallingConvention.Cdecl)] internal static unsafe extern CFunction(ref byte* ptr);

}

Having read the availlable docs, it's not clear to me how to achieve this

realvictorprm commented 6 years ago

That's not possible so far I know.

Am 20.10.2017 02:58 schrieb "raizam" notifications@github.com:

I have a pure C library with structs and function.

I just want to generate minimal bindings without any encapsulation and handle the higher level myself. I'm looking for this kind of layout:

public static class ModuleName { public static unsafe extern CFunction(ref byte* ptr);

}

Having read the availlable docs, it's not clear to me how to achieve this

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mono/CppSharp/issues/989, or mute the thread https://github.com/notifications/unsubscribe-auth/AYPM8JJXGOCK8RdXC6pZ1tKAFhDB5Aaqks5st_AugaJpZM4QADca .

ddobrev commented 6 years ago

@raizam I am not sure what the problem here is. You get more types in your bindings than you need?

raizam commented 6 years ago

The problem is that everything gets encapsulated in class Internal. This is a low level C library and I don't want to get high level C# implementation. Also, cppsharp is not aware about memory ownship of the library and generates a lot of undesired behavior, like Dictionnary mappings between managed/native instances.

And strangely the generated binding shows some mangled c++ functions names while there aren't any.

Anyway...don't bother with this, I'm writing my own parser dedicated for this library

tritao commented 6 years ago

You can easily extend CppSharp to get this functionality. We've had some requests over the years for this and would gladly add it, but so far no one has contributed an actual PR for it.