AaronRobinsonMSFT / DNNE

Prototype native exports for a .NET Assembly.
MIT License
394 stars 41 forks source link

I can not compile my C# library #157

Closed NrSlionHeart closed 1 year ago

NrSlionHeart commented 1 year ago

Steps:

  1. I have created a C# library using .NET 7.0
  2. I have added DNNE to the project
  3. I have added [UnmanagedCallersOnly] or [UnmanagedCallersOnlyAttribute(EntryPoint = "StartsWithUpper")] or whatever versions
  4. When I try to compile I get: "Generated source file(s), obj\x64\Release\net7.0-windows\dnne/TestDLL70.g.c, not found. In order to generate source an export must exist. Create an export by adorning a function with UnmanagedCallersOnly. TestDLL70 C:\Users\lord_.nuget\packages\dnne\2.0.0\build\DNNE.targets 121"

Do I miss some steps here or something?

Because the documentation says: "The DNNE_ASSEMBLY_NAME must be set during compilation to indicate the name of the managed assembly to load. The assembly name should not include the extension. For example, if the managed assembly on disk is called ClassLib.dll, the expected assembly name is ClassLib."

and

"The generated source will need to be linked against the nethost library as either a static lib (libnethost.[lib|a]) or dynamic/shared library (nethost.lib). If the latter linking is performed, the nethost.[dll|so|dylib] will need to be deployed with the export binary or be on the path at run time."

I am a C++ programmer and the whole setting up for this C# project is kinda confusing to me - I had the impression that adding the nuget package should be enough.

Can someone please write a better document with the steps to add DNNE to a project? Like how to actually set DNNE_ASSEMBLY_NAME if that is needed and so on ...

AaronRobinsonMSFT commented 1 year ago

Do I miss some steps here or something?

No, the steps described above are sufficient. As a quick sanity check, can you try using the sample in the repo? See sample/.

I am a C++ programmer and the whole setting up for this C# project is kinda confusing to me - I had the impression that adding the nuget package should be enough.

Yes, that is the case. The details you've mentioned are what is required if someone decides to use the dnne-gen tool directly. However, if the DNNE package is used directly all appropriate flags and settings are passed to the compiler.

NrSlionHeart commented 1 year ago

I downloaded the sample and I could compile it.

I checked if it exports the functions correctly using dependency walker and they seem fine .. like the functions are in there, a lot of missing dependencies, but I assume that can be corrected with the needed files.

I think that this solves my problem for the moment, however does not solve the general problem that it does not compile against a new basically empty project... I assume it is something about the project settings

Thank you anyway!!!

NrSlionHeart commented 1 year ago

And I found what the issue is - when I try to compile a build specifically for x86 I get that error ... any idea how to fix this ?

AaronRobinsonMSFT commented 1 year ago

@NrSlionHeart You should have the x86 version of the runtime installed and specify the RID. See step (3) in readme.md - https://github.com/AaronRobinsonMSFT/DNNE#generating-a-native-binary-using-the-dnne-nupkg.

ThaDaVos commented 1 year ago

About the above - I've got it all working - check that everything is set to x86 - so runtime target but also the platform etc - if it mismatches somewhere it won't compile - also, something I noticed which helps - close Visual Studio - remove the obj and bin folders and re-open the project

ThaDaVos commented 1 year ago

Class Library for Clarion.zip I've created a template for it - maybe it's useful to you - you'll have to import it into Visual Studio and then when the project is created, create your .cs file which will contain your exports - add DNNE - and it should function

AaronRobinsonMSFT commented 1 year ago

Thanks @ThaDaVos. Very much appreciate the shared template.