[swift-users] Binding Regular C Functions (Gtk, Cairo, etc.)

Max Howell max.howell at apple.com
Tue Dec 8 17:30:25 CST 2015


Probably this is a link path issue. Can you open a ticket including your module map and an example source?

https://bugs.swift.org

Thanks,

Max

> From:
>  gagemorgan at outlook.com <mailto:gagemorgan at outlook.com>
> To: mawadah at apple.com <mailto:mawadah at apple.com>
> Subject: RE: [swift-users] Binding Regular C Functions (Gtk, Cairo, etc.)
> Date: Tue, 8 Dec 2015 18:03:42 -0500
> 
> So...including cairo in an app returns this:
> 
> Linking Executable:  .build/debug/example
> /usr/bin/ld: cannot find -l/usr/lib/x86_64-linux-gnu/libcairo.so
> clang: error: linker command failed with exit code 1 (use -v to see invocation)
> <unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
> <unknown>:0: error: build had 1 command failures
> swift-build: exit(1): ["/home/mgage/Downloads/swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu15.10/usr/bin/swift-build-tool", "-f", "/home/mgage/Sources/example/.build/debug/example.o/llbuild.yaml"]
> 
> What went amiss?
> 
> From: mawadah at apple.com <mailto:mawadah at apple.com>
> Subject: Re: [swift-users] Binding Regular C Functions (Gtk, Cairo, etc.)
> Date: Mon, 7 Dec 2015 19:27:56 -0800
> To: gagemorgan at outlook.com <mailto:gagemorgan at outlook.com>
> 
> Once you have followed the instructions to create a system package, your own package declares a dependency on that package. This is also covered in those steps. 
> 
> To use the C APIs in your code, simply import the name of the module (as defined by the modulemap entry) in your swift file. It should just work. 
> 
> For instance, in the example from the sysmodules doc link I sent, you just 
> 
> import CJPEG
> 
> 
> The C functions will have the same name in Swift as their C counterparts. The types might adjust to UnsafePointer etc.. For a list of those Swift bindings, run the REPL and import your module, then perform “:type lookup Module” to get a printout of available APIs.
> 
> - mish
> 
> On Dec 7, 2015, at 6:40 PM, Gage Morgan <gagemorgan at outlook.com <mailto:gagemorgan at outlook.com>> wrote:
> 
> I read that. What I want to know is how to bind the functions themselves after creating a system package. How to use the c functions that got imported, if you will. 
> 
> Sent from Outlook <http://aka.ms/Ox5hz3>
> 
> 
> 
> On Mon, Dec 7, 2015 at 6:39 PM -0800, "Mish Awadah" <mawadah at apple.com <mailto:mawadah at apple.com>> wrote:
> 
> Please see the reference at https://github.com/apple/swift-package-manager/blob/master/Documentation/SystemModules.md <https://github.com/apple/swift-package-manager/blob/master/Documentation/SystemModules.md>
> 
> - mish
> 
> On Dec 7, 2015, at 6:33 PM, Gage Morgan via swift-users <swift-users at swift.org <mailto:swift-users at swift.org>> wrote:
> 
> For any project: How is a C to Swift function binding created? I'd like to know how to import C functions to Swift. Once I can do this successfully, I'll be all set. 
> 
> Sent from Outlook <http://aka.ms/Ox5hz3>
>  _______________________________________________
> swift-users mailing list
> swift-users at swift.org <mailto:swift-users at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-users <https://lists.swift.org/mailman/listinfo/swift-users>
> 
> 
>  _______________________________________________
> swift-users mailing list
> swift-users at swift.org <mailto:swift-users at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-users <https://lists.swift.org/mailman/listinfo/swift-users>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20151208/6b22c2ab/attachment.html>


More information about the swift-users mailing list