I'm trying to create a Swifified version of the allegro game library (```brew install pkg-config allegro``) and it feels like I'm almost there but I'm missing a crucial step as the functions of the library aren't visible from the Swift side.
The package can be found here: GitHub - SwiftStudies/Allegro: Swiftied version of the Allegro 5 C game library
I'm getting an error that al_init() is an unresolved identifier. This is the only error I get from the build process (everything else... finding headers etc seems to work fine now)
As a quick test I added a string constant to the c header for the system library target and that is found and builds fine (see Allegro.version in Allegro.swift).
What am I doing wrong?
jrose
(Jordan Rose)
2
It looks like al_init is a macro, not a real function. Swift only knows how to handle very simple macros at this time. However, you should be able to expand the macro yourself to handle this.
2 Likes
Oh thank you. It's been so long since I've done any C I had forgotten how you don't really know what anything is!
1 Like
Aciid
(Ankit Aggarwal)
4
A useful trick is looking at the swift interface of the C library by generating an Xcode project using swift package generate-xcodeproj.
2 Likes
I love that idea... but really dumb question... once in Xcode how do I do that? The generated project is excluding the c/h files, so I can't see them there... and the only "Product" is the final framework which doesn't expose any of these things...
What am I not seeing?
Forget it! Right click on the CAllegro import!
Thank you SO much... pro tip!!!
1 Like