-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minimal examples fail to generate or crash with NullReferenceException #221
Comments
I assume you saw #101? That appears to be the same issue, and the fix mentioned there worked for me. |
Hey, thanks for replying to such an old issue. During that investigation I did not see #101 and I was just about to look into SharpGenTools again to see if it would now be usable for my use case. What a cool coincidence! |
Haha no worries, I've been trying to use it for the first time recently, with mediocre results so far. I also encountered this same problem and found both issues, thought I'd link them in case anyone else stumbles into the same problem in the future. Honestly I'm not impressed by SharpGenTools, but I did eventually get it working on a basic level. I'm probably just going to use it one time to get 80% of the way there, then copy out the generated code and hand-edit it from there. |
I got it to compile something useful now, but it does give me an EntryPointNotFoundException when running it. This is probably me doing something wrong in the C++ dll: Header:
class file:
But its not immediately obvious to me what's going wrong. |
I think you may need to tack on #include "NativeFunctions.h"
#include "pch.h"
extern "C" int Fourteen()
{
return 14;
} But I may be wrong, far from a C/C++ expert. |
I got it now, the code was basically correct but I needed to do some tinkering with the settings of the C++ project. To make sure this is repeatable, and that I don't forget how to do this, I've created a tiny working example and published it in this repository: https://github.com/roy-t/SharpGenToolsExample. |
By the way, I think that there is a beta release that has a lot more features. I see that Vortice for example uses version 2.0.0-beta.13. And from my experience Vortice works great: https://github.com/amerkoleci/Vortice.Windows/blob/main/Directory.Packages.props Maybe that generates better code for you? |
@roy-t You can use my branch. I fixed a lot of bugs and added some new features. |
Thanks Mikhail! |
I'm trying to get started with SharpGen. But I think I'm either missing an important configuration aspect or installed component. Because I can't even get the most minimal case to work. Let me show, two examples.
In all cases the csproj file looks like this:
Example 1, mapping a single function
I've got the following header file
encoder.h
And the following
Mappings.xml
fileThis fails with the following error:
If I remove the
<mapping>
part I get the following error, so it looks like it is at least correctly reading the header file:Example 2, just auto attach a class
So I thought to myself, ok, maybe I misunderstand mappings, let's try to just auto-attach a simple class. So I changed my header file to:
And my mappings file to:
This does not crash, but only generates the following empty struct:
The cause?
Maybe I'm doing something completely wrong? I've been looking at how SharpGen is used in Vortice, and it looks similar. I've also been following the guide at https://sharpgentools.readthedocs.io/en/latest/index.html, but that is a few years old (2018), so maybe its out of date?
I'm running an up-to-date Visual Studio 2022 on Windows 10 (19044.1766) and I've go the .Net Desktop and Desktop Development with C++ workloads installed, together with Windows SDK (10.0.19041.0)
Side note
When I started out with SharpGen I tried to map a class with a
std::string
in it, that caused an error that Clang was too oldCX0002 #error STL1000: Unexpected compiler version, expected Clang 13.0.0 or newer.
However clang inC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\x64\bin\clang.exe
is version13.0.1
. I never was able to resolve that error and then moved to testing more simple cases. But maybe that's a hint something else is wrong?The text was updated successfully, but these errors were encountered: