bottlenoselabs / c2cs

Generate C# bindings from a C header.
MIT License
250 stars 18 forks source link

Eh it is sometime errors :( #141

Closed DeafMan1983 closed 1 year ago

DeafMan1983 commented 1 year ago

Hello, I have followed step to step

  1. Create json ( config.json )
  2. castffi extract It said Unrecognized command or argument 'config.json'.
  3. Try with c2cs and find config.json then it said still errors. But why does it give errors for me?
    2023-20-04 14:17:27 info: C2CS.WriteCodeCSharp.WriteCodeCSharpTool[0] - Started
    2023-20-04 14:17:27 info: C2CS.WriteCodeCSharp.WriteCodeCSharpTool[2] - Failed in 0.0093 seconds
    2023-20-04 14:17:27 crit: C2CS.WriteCodeCSharp.WriteCodeCSharpTool[0] - Panic The output file path can not be an empty or null string.    at C2CS.WriteCodeCSharp.Input.WriteCodeCSharpInputSanitizer.OutputFilePath(String outputFilePath) in /home/runner/work/c2cs/c2cs/src/cs/production/C2CS.Tool/WriteCodeCSharp/Input/WriteCodeCSharpInputSanitizer.cs:line 88    at C2CS.WriteCodeCSharp.Input.WriteCodeCSharpInputSanitizer.Sanitize(WriteCSharpCodeOptions unsanitizedInput) in /home/runner/work/c2cs/c2cs/src/cs/production/C2CS.Tool/WriteCodeCSharp/Input/WriteCodeCSharpInputSanitizer.cs:line 30    at C2CS.Foundation.Tool.Tool`3.Run(TUnsanitizedInput unsanitizedInput, String workingFileDirectory) in /home/runner/work/c2cs/c2cs/src/cs/production/C2CS.Tool/Foundation/Tool/Tool.cs:line 125

What is the hell?

I expect that generator of p/invoke won't work for Ubuntu 22.04. I have already tried ClangSharp = Not working! c2cs = also not working... Ah please stop taking advantage my time!

My config.json for Linux is:

{
    "inputFilePath": "/usr/include/SDL/SDL.h",
    "userIncludeDirectories": [
        "/usr/include"
    ],
    "platform": {
        "x86_64-unknown-linux-gnu": {}
    }
}

It has not wrong characters.

Thanks sorry I hesitate about generator for p/invoke

lithiumtoast commented 1 year ago

Unrecognized command or argument 'config.json'.

It's c2cs --config /path/to/config.json

lithiumtoast commented 1 year ago

With C2CS version 5, the config.json you posted is first for CAstFfi.

castffi extract /path/to/config-linux.json castffi merge --inputDirectoryPath /path/to/ast/directory --outputFilePath /path/to/cross-platform-ast.json c2cs --config /path/to/config-cs.json

config-linux.json:

{
  "inputFilePath": "/usr/include/SDL/SDL.h",
  "userIncludeDirectories": [
    "/usr/include/SDL"
  ],
  "platforms": {
    "x86_64-unknown-linux-gnu": {},
  }
}

config-cs.json:

{
  "inputFilePath": "/path/to/cross-platform-ast.json",
  "outputFilePath": "/path/to/SDL.cs",
  "namespaceName": "",
  "className": "SDL"
}
DeafMan1983 commented 1 year ago

Okay thanks I will try again....

Oh I found generator can't find SDL_FillRect()

Unhandled exception. System.EntryPointNotFoundException: Unable to find an entry point named 'SDL_FillRect' in shared library 'SDL3'.
   at bottlenoselabs.SDL.SDL_FillRect(SDL_Surface* dst, SDL_Rect* rect, UInt32 color)

I already downloaded and tested from repository of your helloworld and it shows FillRect has not SDL_FillRect() It is impossible? I believe it is new version won't use longer with old SDL_FillRect()....

lithiumtoast commented 1 year ago

You may need to re-point the SDL submodule to v2; perhaps in v3 of SDL SDL_FillRect is no longer there?

DeafMan1983 commented 1 year ago

Yes check out new version of SDL3 but I have already released SDL3 with ClangSharpPInvokeGenerator. Can you check my repository DeafMan1983.Interop.SDL3

If you have problem with sbyte * or string conversion.

Then you can try out if you have example sdl2/3 with SDL3 C#.

Enjoy your happy development! You can find in nuget.org also both packages. But both support Net 7.0