xlab / c-for-go

Automatic C-Go Bindings Generator for Go Programming Language
https://c.for-go.com
MIT License
1.47k stars 116 forks source link

How to add a Framework? #129

Open danjenkins opened 2 years ago

danjenkins commented 2 years ago

I've offered up CFLAGS and LDFLAGS for how to find the CoreFoundation framework but while it's processing the file given in Includes in the GENERATOR section...it fails to find the framework during the processing step

processing decklink.yml ⠋[ERR] ./sdk/Mac/include/DeckLinkAPI.h:46:10: include file not found: CoreFoundation/CoreFoundation.h. Search paths:

The search paths don't note the flags....

Here are the flags given...

  FlagGroups:
    - name: CFLAGS
      traits: ["darwin"]
      flags:
        - "-F/Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk/System/Library/Frameworks"
        - "-framework CoreFoundation"
    - name: LDFLAGS
      traits: ["darwin"]
      flags:
        - "-F/Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk/System/Library/Frameworks"
        - "-framework CoreFoundation"

If anyones got any ideas that would be great :D

EDIT:

My parser section looks like...

PARSER:
  IncludePaths:
    - /usr/include
    - /usr/local/include
  SourcesPaths:
    - ./sdk/Mac/include/DeckLinkAPI.h
  Arch: aarch64

But then theres no way to provide framework's to the parser section?

xlab commented 2 years ago

1) Parser uses those paths to find and parse headers. Usually I plug in the frameworks only to provide symbols for linking, i.e. in LDFLAGS.

2) Parsing frameworks (OS X) folders weren't feasible before, as it contained too much VERY advanced code constructs, and CCv1 (the previous parser) wasn't able to handle it. After this PR https://github.com/xlab/c-for-go/pull/127 which upgraded to new parser CCv4 the situation might've changed.

3) If you need to provide frameworks for linking, the best way is to put those flags into a separate file manually, because using that in FlagGroups means that it will be included in every Go file generated. Which is not always a problem, but just doesn't look nice.

Example file: https://github.com/vulkan-go/vulkan/blob/master/vulkan_darwin.go (I did it manually)

Also, check out how folks at GLFW do it: https://github.com/go-gl/glfw/blob/master/v3.3/glfw/build.go

xlab commented 2 years ago

If you don't mind sharing a minimal reproducible example.. I can try :D

danjenkins commented 2 years ago

hey @xlab here's the repo - https://github.com/broadcastervc/go-decklink - I wouldnt call the Decklink SDK minimal though :(

The Decklink SDK is a c++ sdk with "extern C" which should mean it's usable by c-for-go ?

To get c-for-go to be happy with the files on linux I needed to add struct before REFIID in a few files. The files would all get processed correctly but then I'm stuck on what I need to add to the yml file to make it output functions.

I still can't get past the CoreFoundation framework on mac though even after upgrading to the latest version of c-for-go

xlab commented 2 years ago

I wouldnt call the Decklink SDK minimal though

I am not afraid of big examples :D Just mentioned minimal in case you don't want to share the full code.

which should mean it's usable by c-for-go ?

true!

I still can't get past the CoreFoundation framework

I will try on this week.

danjenkins commented 1 year ago

hey @xlab did you ever get a chance to take a look at this? just coming back to it now myself.