Generating pinvoke wrappers using ClangSharpPInvokeGenerator generates CXError_Failure errors
See original GitHub issueI’m trying to generate pinvoke wrappers for poppler cpp header files on ubuntu.
You can see the code for those those headers here https://gitlab.freedesktop.org/poppler/poppler/-/blob/master/cpp/poppler-font.h
Poppler is installed on my system via apt
I’m running the generate tool as follows
~/.dotnet/tools/ClangSharpPInvokeGenerator @generate.rsp
The response file looks like the following
--config
compatible-codegen
generate-tests-xunit
multi-file
unix-types
log-potential-typedef-remappings
log-visited-files
--file
poppler-font.h
poppler-document.h
poppler-page.h
poppler-toc.h
poppler-version.h
--namespace
Popper.Interop
--output
./output
--test-output
./tests
--include-directory
/usr/include/poppler/cpp
/usr/include/poppler
--language
c++
I’m using the 11.0.0-beta3 tool installed globally
dotnet tool install --global ClangSharpPInvokeGenerator --version 11.0.0-beta3
Version of clang is the following
❯ clang --version
clang version 10.0.0-4ubuntu1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Whenever I run the generator tool, I get the following errors
Error: Parsing failed for 'poppler-font.h' due to 'CXError_Failure'.
Skipping 'poppler-font.h' due to one or more errors listed above.
Error: Parsing failed for 'poppler-document.h' due to 'CXError_Failure'.
Skipping 'poppler-document.h' due to one or more errors listed above.
Error: Parsing failed for 'poppler-page.h' due to 'CXError_Failure'.
Skipping 'poppler-page.h' due to one or more errors listed above.
Error: Parsing failed for 'poppler-toc.h' due to 'CXError_Failure'.
Skipping 'poppler-toc.h' due to one or more errors listed above.
Error: Parsing failed for 'poppler-version.h' due to 'CXError_Failure'.
Skipping 'poppler-version.h' due to one or more errors listed above.
I’m trying to figure out why this tool is failing, but the errors don’t tell me much. Is there any way for me to get more information? Just trying to figure out what the next steps should be.
Thanks for your help.
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
dotnet/ClangSharp: Clang bindings for .NET written in ...
It is self-hosted and auto-generates itself by parsing the Clang C header files using ClangSharpPInvokeGenerator. ci. A nuget package for the project is ......
Read more >Generating .NET interop bindings via ClangSharp
Let's make it prettier by splitting things into multiple files and using file scoped namespaces. powershell. ClangSharpPInvokeGenerator ` -c ...
Read more >P/Invoke source generation
NET 7 introduces a source generator for P/Invokes that recognizes the LibraryImportAttribute in C# code. When it's not using source ...
Read more >Platform Invoke (P/Invoke)
P/Invoke is a technology that allows you to access structs, callbacks, and functions in unmanaged libraries from your managed code.
Read more >pinvoke.net: the interop wiki!
Manually defining and using PInvoke signatures is an error-prone process that can introduce subtle bugs. PInvoke.net supplies you with tried and tested ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m definitely fine with some additional hints in the docs or even in the failure case on the command line.
Most of the time right now we only expose what libClang itself reports, which is often less than helpful.
Hmmm. I just tried on a clean machine and everything looks to work as expected.
ClangSharp 13.0.0
I did the following
sudo apt install git gcc clang-13 llvm-13-devgit clone https://github.com/microsoft/clangsharpcd ./clangsharpOVERRIDE_RUNTIME_IDENTIFIER=ubuntu.20.04-x64./scripts/cibuild.sh --ciThat failed, so I then did:
sudo cp ~/.nuget/packages/libclangsharp.runtime.ubuntu.20.04-x64/13.0.0-beta1/runtimes/ubuntu.20.04-x64/native/libClangSharp.so /usr/lib/x86_64-linux-gnu/libClangSharp.so./scripts/cibuild.sh --ciAnd everything succeeded.
ClangSharp 12.0.0
I did the following:
sudo apt install git gcc clang-12 llvm-12-devdotnet tool install --global ClangSharpPInvokeGenerator --version 12.0.0-beta2sudo cp ~/downloads/libclangsharp.runtime.ubuntu.20.04-x64/12.0.0-beta1/runtimes/ubuntu.20.04-x64/native/libClangSharp.so /usr/lib/x86_64-linux-gnu/libClangSharp.soecho "void M();" > Test.hClangSharpPInvokeGenerator --file Test.h -n Test -o ./Test.csThat failed with the type load error, so I did:
ldd /usr/lib/x86_64-linux-gnu/libClangSharp.solibclang.so.12couldn’t be resolved, as you sawsudo ln -s /usr/lib/x86_64-linux-gnu/libclang-12.so.1 /usr/lib/x86_64-linux-gnu/libclang.so.12ClangSharpPInvokeGenerator --file Test.h -n Test -o ./Test.csAnd everything succeeded.