I have found the DllExport Project on GitHub while searching for a way to use C# .NET Core 3 Code from Plain C/C++. My goal is being able to compile the C# to any dynamic library and use it on both Linux or Windows with dlopen (dlopen for Windows).
C# Library I'm trying to create:
using RGiesecke.DllExport;
using System;
namespace CSharpPart
{
public class Test
{
[DllExport]
public static int _add(int a, int b)
{
return a + b;
}
}
}
C/C++ Code where I'm trying to Reference the C# Library:
#include "CPartCMake.h"
#include "dlfcn.h"
#include "cstring"
using namespace std;
int main()
{
const char* pemodule = "path_to_dll\\CSharpPart.dll";
void* handle = dlopen(pemodule, RTLD_NOW);
typedef int(_cdecl* _add)(int a, int b);
_add pAdd = (_add)dlsym(handle, "_add");
cout << pAdd(5, 7);
return 0;
}
The Call to dlopen returns a non NULL handle which I guess means that the Library itself can be opened. dlsym return a NULL. When viewing the C# DLL through DLL Export Viewer it can be confirmed that the DLL doesn't contain the _add entry.
I tried Wrapping the C# project in an C++/CLI Project like proposed here but it doesn't seems to work with .NET Core.
I read there is also a possibility with using COM interop but I didn't really understood what it is about and I'm not sure if it would work cross-platform like.
I'm afraid that DLLExport just isn't yet compatible with .NET Core as well. Is there any way of achieving my goal like I described it?