xoofx / CppAst.NET

CppAst is a .NET library providing a C/C++ parser for header files powered by Clang/libclang with access to the full AST, comments and macros
BSD 2-Clause "Simplified" License
482 stars 63 forks source link

clang_EnumDecl_isScoped not found #43

Closed danyhm closed 3 years ago

danyhm commented 3 years ago

Hi,

after a long day, I finally managed to supply the right arguments for the MingW64 8.1.0 Include folders and try to parse a header based on that.

however I think the Enum parser is broken (all other parsers work fine) , and when the parser sees an enum i get this exception in the visual studio 2019 debugger :

System.EntryPointNotFoundException: 'Unable to find an entry point named 'clang_EnumDecl_isScoped' in DLL 'libclang'.'
in CppModelBuilder.cs line 1039:cppEnum.IsScoped = cursor.EnumDecl_IsScoped;

the same error is produced if I try the sample from the main page with an enum in it:

var compilation = CppParser.Parse(@"
enum MyEnum { MyEnum_0, MyEnum_1 };
void function0(int a, int b);
struct MyStruct { int field0; int field1;};
typedef MyStruct* MyStructPtr;
"
);

any ideas?

xoofx commented 3 years ago

Which version of CppAst.NET are you using?

danyhm commented 3 years ago

I cloned the git repo, so I'm on the last commit of the master branch.

xoofx commented 3 years ago

Can't reproduce this on master + Windows. Are you running on Linux or MacOS maybe?

xoofx commented 3 years ago

Also inspecting the local libclang.dll file and I can see the symbol clang_EnumDecl_isScoped exported, so I believe that you have something weird on your setup as it doesn't seem to load the correct libclang.dll.

danyhm commented 3 years ago

I'm on windows. and you're right the function is exported. this is very strange. i think it has to be something related to .net platform maybe?

xoofx commented 3 years ago

Can you share your csproj?

danyhm commented 3 years ago

yes sure

CppAst.NET-error.zip

xoofx commented 3 years ago

Ok, so that's because you need to add this line to your csproj:

  <PropertyGroup>
    <!-- Workaround for issue https://github.com/microsoft/ClangSharp/issues/129 -->
    <RuntimeIdentifier Condition="'$(RuntimeIdentifier)' == '' AND '$(PackAsTool)' != 'true'">$(NETCoreSdkRuntimeIdentifier)</RuntimeIdentifier>
  </PropertyGroup>

as it is done in the tests, otherwise it won't copy the correct libclang DLL and might start to use another mismatching arch on your path... Same if you consume the package.

danyhm commented 3 years ago

thanks ! that solved the problem !

xoofx commented 3 years ago

Great. Related Runtime packages not restoring properly? on ClangSharp and Improve handling of native packages on NuGet