Closed chschrae closed 1 year ago
@chschrae Thanks for the suggestion. There are two options and each of them changes depending on what platform is being targeted. Let me share how to do this in Windows.
1) Load the generated native binary (for example, SampleNE.dll
) via LoadLibrary()
and then lookup the export using GetProcAddress()
.
2) Include generated header file (for example, SampleNE.h
) and link against the export lib (for example, SampleNE.lib
).
@AaronRobinsonMSFT The route I am taking is # 2. I am having trouble understanding some of the readme though. I link to SampleNE.lib in my AdditionalDependencies in VS and copies the library output from the existing sample project to a directory under my new on. I still get an error around the dnne.h header not being found.
If I copy the dnne.h and reference it directly with quotes it is fine, but I feel like I am missing a library link somewhere that should handle that for me.
I have created a sample native project that consumes the sample managed project and gotten it to run on windows with some hacks, but I feel like it isn't the intended consumption. I did not have to set a DNNE_ASSEMBLY_NAME like referenced in the readme and I am also not including the nethost lib anywhere.
If I copy the dnne.h and reference it directly with quotes it is fine, but I feel like I am missing a library link somewhere that should handle that for me.
Both the SampleNE.h
and the dnne.h
headers should be copied with the SampleNE.lib
for use during build. The linker gets the lib name and the include paths should be updated to point to where ever the headers are located. The SampleNE.dll
, Sample.dll
and Sample.runtimeconfig.json
should be copied for use at run time.
I can provide an example, but it likely wouldn't be as a Visual Studio solution, rather it would be a CMake project and require some trickery. Chaining all this together with a C++ project in Visual Studio is going to be a challenge in general. The two project systems are designed in different ways and don't mesh well together. My recommendation is to have a post build set for the managed project and that copies assets to a specific output directory where the C++ project can reference. This could also be done by having two solutions, but that is likely not your desire.
Mixing managed and native projects in Visual Studio and having them depend on each other is a well known issue and something that doesn't have a well-defined solution to my knowledge. If you find one I am happy to include at reference.
Hi there!
It would be really helpful if in the sample directory there was also a sample consuming project that showed examples of how to link and copy the exported libraries. I feel like the readme doesn't quite give enough to answer all my questions and I am spending time figuring it out.