Problem with latest ClangSharpPInvokeGenerator
Hello,
I have tried #586 ( I already installed dotnet tool install clangsharppinvokegenerator, dotnet add package libclang-runtime-linux-x64 and dotnet add package libclangsharp-runtime-linux-x64
And I already installed clang and buildessential etc.
Why does it happen because it has error:
ClangSharpPInvokeGenerator --file /usr/include/CL/cl.h -n OpenCL --methodClassName CLInterop --libraryPath libOpenCL.so -o CSharp/Class.cs -i /usr/lib/gcc/x86_64-linux-gnu/13/include -i /usr/include
Diagnostics for '/usr/include/CL/cl.h':
/usr/include/CL/cl_platform.h:362:10: fatal error: 'stddef.h' file not found
Skipping '/usr/include/CL/cl.h' due to one or more errors listed above.
And I checked find command:
find /usr -name stddef.h
/usr/include/linux/stddef.h
/usr/src/linux-headers-6.8.0-51/include/uapi/linux/stddef.h
/usr/src/linux-headers-6.8.0-51/include/linux/stddef.h
/usr/lib/llvm-18/lib/clang/18/include/stddef.h
/usr/lib/llvm-17/lib/clang/17/include/stddef.h
/usr/lib/gcc/x86_64-linux-gnu/13/include/stddef.h
I have tried and it tells same skipping error cause I want to port to C# with OpenCL because it said error of stddef.h
How do I fix it? Please forgive me!
https://github.com/dotnet/ClangSharp/issues/586#issuecomment-2658015030
The tool-supplied libclang apparantly does not search for compiler-supplied headers; many Linux systems does not come with headers like stddef.h in /usr/include, relying instead on the compiler to supply them.
An interim solution in the meantime is to add the compiler-supplied headers to -I, preferrably ones from Clang 20. On Fedora, Clang 20 puts its own system headers in /usr/lib/clang/20/include.
Right. This is just a consideration of how libClang itself works. It is the responsibility of the caller to pass down any include directories, just as would be required for any other tool consuming the official libClang exports provided by LLVM.
It is a non-goal of the tool to try and emulate the clang command line tool (or other build tools like cmake) and mirror any special logic or handling it does, particularly as that logic tends to be very machine specific and has breaking changes over time. A lot of this is extremely complex logic that is dependent on many variables and customization options that are outside the scope of this tool (which is not aiming to be a full fledged build tool).