Generating pinvoke wrappers using ClangSharpPInvokeGenerator generates CXError_Failure errors

See original GitHub issue

I’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:closed
  • Created 2 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
tannergoodingcommented, Oct 31, 2021

Would you be ok if I submitted a PR for the README with some of these steps in there? Or do you think this would change too often to be useful?

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.

1reaction
tannergoodingcommented, Oct 31, 2021

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-dev
  • git clone https://github.com/microsoft/clangsharp
  • cd ./clangsharp
  • OVERRIDE_RUNTIME_IDENTIFIER=ubuntu.20.04-x64
  • ./scripts/cibuild.sh --ci

That 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 --ci

And everything succeeded.

ClangSharp 12.0.0

I did the following:

That failed with the type load error, so I did:

  • ldd /usr/lib/x86_64-linux-gnu/libClangSharp.so
    • This shows libclang.so.12 couldn’t be resolved, as you saw
  • sudo ln -s /usr/lib/x86_64-linux-gnu/libclang-12.so.1 /usr/lib/x86_64-linux-gnu/libclang.so.12
  • ClangSharpPInvokeGenerator --file Test.h -n Test -o ./Test.cs

And everything succeeded.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found