Linux - How to use C libs


(Damien (dev)) #1

Hello Again,

Now that I have a functional Swift installation, I'd like to know if/how I
can use C libs ?
How do I import headers & link to the right libs ?

Thanks


(René Cacheaux) #2

Chris Eidhof gave a talk on using C libs in Swift that might be helpful: https://realm.io/news/pragma-chris-eidhof-swift-c/

Cheers,
Rene

···

Sent from my iPhone

On Dec 5, 2015, at 7:58 AM, Damien BRUN <dev@lanza.fr> wrote:

Hello Again,

Now that I have a functional Swift installation, I'd like to know if/how I can use C libs ?
How do I import headers & link to the right libs ?

Thanks

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


(Harlan Haskins) #3

C libraries require you to create modules for them. There's a great guide with examples for importing libjpeg into Swift on GitHub:

https://github.com/apple/swift-package-manager/blob/master/Documentation/SystemModules.md

···

On Dec 5, 2015, at 8:58 AM, Damien BRUN <dev@lanza.fr> wrote:

Hello Again,

Now that I have a functional Swift installation, I'd like to know if/how I can use C libs ?
How do I import headers & link to the right libs ?

Thanks

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


(Damien (dev)) #4

Thanks Harlan for the link, this is what I'm trying to do. =)

With interdependent libs, this becomes a mess anyway... (tried gdk/gtk...)

& thanks René for the video. Very interesting for what will come next.

···

2015-12-05 18:07 GMT+01:00 Harlan Haskins <harlan@harlanhaskins.com>:

C libraries require you to create modules for them. There's a great guide
with examples for importing libjpeg into Swift on GitHub:

https://github.com/apple/swift-package-manager/blob/master/Documentation/SystemModules.md

On Dec 5, 2015, at 8:58 AM, Damien BRUN <dev@lanza.fr> wrote:

Hello Again,

Now that I have a functional Swift installation, I'd like to know if/how I
can use C libs ?
How do I import headers & link to the right libs ?

Thanks

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


(Damien (dev)) #5

Works with simple libs which can be referenced by a simple path.
With Gdk/Gtk who share a single include dir, module compilation can't
find its way.
No matter what I try, I end up with :

<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "gtk/gtk.h"
             ^
/usr/include/gtk-3.0/gtk/gtk.h:30:10: error: 'gdk/gdk.h' file not found
#include <gdk/gdk.h>

Seems like one would have to rewrite gtk/gdk headers to please clang...

···

2015-12-05 19:40 GMT+01:00 Damien BRUN <dev@lanza.fr>:

Thanks Harlan for the link, this is what I'm trying to do. =)

With interdependent libs, this becomes a mess anyway... (tried gdk/gtk...)

& thanks René for the video. Very interesting for what will come next.

2015-12-05 18:07 GMT+01:00 Harlan Haskins <harlan@harlanhaskins.com>:

C libraries require you to create modules for them. There's a great guide with examples for importing libjpeg into Swift on GitHub:

https://github.com/apple/swift-package-manager/blob/master/Documentation/SystemModules.md

On Dec 5, 2015, at 8:58 AM, Damien BRUN <dev@lanza.fr> wrote:

Hello Again,

Now that I have a functional Swift installation, I'd like to know if/how I can use C libs ?
How do I import headers & link to the right libs ?

Thanks

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


(Mish Awadah) #6

Please file a bug describing the situation and your environment. We’d be happy to make this easier for you in the future.

- mish

···

On Dec 5, 2015, at 11:51 AM, Damien BRUN via swift-users <swift-users@swift.org> wrote:

Works with simple libs which can be referenced by a simple path. With Gdk/Gtk who share a single include dir, module compilation can't find its way. No matter what I try, I end up with :

<module-includes>:1:10: note: in file included from <module-includes>:1: #include “gtk/gtk.h”

^
/usr/include/gtk-3.0/gtk/gtk.h:30:10: error: ‘gdk/gdk.h’ file not found #include <gdk/gdk.h>

Seems like one would have to rewrite gtk/gdk headers to please clang…

2015-12-05 19:40 GMT+01:00 Damien BRUN <dev@lanza.fr>:

Thanks Harlan for the link, this is what I'm trying to do. =)
With interdependent libs, this becomes a mess anyway... (tried gdk/gtk...)
& thanks René for the video. Very interesting for what will come next.
2015-12-05 18:07 GMT+01:00 Harlan Haskins <harlan@harlanhaskins.com>:
C libraries require you to create modules for them. There's a great guide with examples for importing libjpeg into Swift on GitHub:
https://github.com/apple/swift-package-manager/blob/master/Documentation/SystemModules.md
On Dec 5, 2015, at 8:58 AM, Damien BRUN <dev@lanza.fr> wrote:
Hello Again,
Now that I have a functional Swift installation, I'd like to know if/how I can use C libs ?
How do I import headers & link to the right libs ?
Thanks
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users
_____________________________________________ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users


(Max Howell) #7

Indeed, this *should* work, and if we have to do some tricks to make it do so we’re happy to make the modifications, so please file a bug and we’ll look into it. Thanks.

Max

···

On Dec 7, 2015, at 11:06 AM, Mish Awadah via swift-users <swift-users@swift.org> wrote:

Please file a bug describing the situation and your environment. We’d be happy to make this easier for you in the future.

- mish

On Dec 5, 2015, at 11:51 AM, Damien BRUN via swift-users <swift-users@swift.org <mailto:swift-users@swift.org>> wrote:

Works with simple libs which can be referenced by a simple path. With Gdk/Gtk who share a single include dir, module compilation can't find its way. No matter what I try, I end up with :

<module-includes>:1:10: note: in file included from <module-includes>:1: #include “gtk/gtk.h”

^
/usr/include/gtk-3.0/gtk/gtk.h:30:10: error: ‘gdk/gdk.h’ file not found #include <gdk/gdk.h>

Seems like one would have to rewrite gtk/gdk headers to please clang…

2015-12-05 19:40 GMT+01:00 Damien BRUN <dev@lanza.fr <mailto:dev@lanza.fr>>:

Thanks Harlan for the link, this is what I'm trying to do. =)
With interdependent libs, this becomes a mess anyway... (tried gdk/gtk...)
& thanks René for the video. Very interesting for what will come next.
2015-12-05 18:07 GMT+01:00 Harlan Haskins <harlan@harlanhaskins.com <mailto:harlan@harlanhaskins.com>>:
C libraries require you to create modules for them. There's a great guide with examples for importing libjpeg into Swift on GitHub:
https://github.com/apple/swift-package-manager/blob/master/Documentation/SystemModules.md
On Dec 5, 2015, at 8:58 AM, Damien BRUN <dev@lanza.fr <mailto:dev@lanza.fr>> wrote:
Hello Again,
Now that I have a functional Swift installation, I'd like to know if/how I can use C libs ?
How do I import headers & link to the right libs ?
Thanks
_______________________________________________
swift-users mailing list
swift-users@swift.org <mailto:swift-users@swift.org>
https://lists.swift.org/mailman/listinfo/swift-users
_____________________________________________ swift-users mailing list swift-users@swift.org <mailto:swift-users@swift.org> https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


(Stepan Hruda) #8

Can confirm that it works through spm and a modulemap.

···

On Mon, Dec 7, 2015 at 6:13 PM Max Howell via swift-users < swift-users@swift.org> wrote:

Indeed, this *should* work, and if we have to do some tricks to make it do
so we’re happy to make the modifications, so please file a bug and we’ll
look into it. Thanks.

Max

On Dec 7, 2015, at 11:06 AM, Mish Awadah via swift-users < > swift-users@swift.org> wrote:

Please file a bug describing the situation and your environment. We’d be
happy to make this easier for you in the future.

- mish

On Dec 5, 2015, at 11:51 AM, Damien BRUN via swift-users < > swift-users@swift.org> wrote:

Works with simple libs which can be referenced by a simple path. With
Gdk/Gtk who share a single include dir, module compilation can't find its
way. No matter what I try, I end up with :

<module-includes>:1:10: note: in file included from <module-includes>:1:
#include “gtk/gtk.h”

^

/usr/include/gtk-3.0/gtk/gtk.h:30:10: error: ‘gdk/gdk.h’ file not found
#include <gdk/gdk.h>

Seems like one would have to rewrite gtk/gdk headers to please clang…

2015-12-05 19:40 GMT+01:00 Damien BRUN <dev@lanza.fr>:

Thanks Harlan for the link, this is what I'm trying to do. =)

With interdependent libs, this becomes a mess anyway... (tried gdk/gtk...)

& thanks René for the video. Very interesting for what will come next.

2015-12-05 18:07 GMT+01:00 Harlan Haskins <harlan@harlanhaskins.com>:

C libraries require you to create modules for them. There's a great guide with examples for importing libjpeg into Swift on GitHub:

https://github.com/apple/swift-package-manager/blob/master/Documentation/SystemModules.md

On Dec 5, 2015, at 8:58 AM, Damien BRUN <dev@lanza.fr> wrote:

Hello Again,

Now that I have a functional Swift installation, I'd like to know if/how I can use C libs ?
How do I import headers & link to the right libs ?

Thanks

_______________________________________________
swift-users mailing listswift-users@swift.orghttps://lists.swift.org/mailman/listinfo/swift-users

*____________________________________________*_ swift-users mailing list
swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


(Damien (dev)) #9

Filed it. Issue SR-179.

Stephan, can you share the modulemap you used ?

···

--
Damien BRUN

Le 8 déc. 2015 à 06:19, Stepan Hruda via swift-users <swift-users@swift.org> a écrit :

Can confirm that it works through spm and a modulemap.

On Mon, Dec 7, 2015 at 6:13 PM Max Howell via swift-users <swift-users@swift.org> wrote:
Indeed, this *should* work, and if we have to do some tricks to make it do so we’re happy to make the modifications, so please file a bug and we’ll look into it. Thanks.

Max

On Dec 7, 2015, at 11:06 AM, Mish Awadah via swift-users <swift-users@swift.org> wrote:

Please file a bug describing the situation and your environment. We’d be happy to make this easier for you in the future.

- mish

On Dec 5, 2015, at 11:51 AM, Damien BRUN via swift-users <swift-users@swift.org> wrote:

Works with simple libs which can be referenced by a simple path. With Gdk/Gtk who share a single include dir, module compilation can't find its way. No matter what I try, I end up with :

<module-includes>:1:10: note: in file included from <module-includes>:1: #include “gtk/gtk.h”

^
/usr/include/gtk-3.0/gtk/gtk.h:30:10: error: ‘gdk/gdk.h’ file not found #include <gdk/gdk.h>

Seems like one would have to rewrite gtk/gdk headers to please clang…

2015-12-05 19:40 GMT+01:00 Damien BRUN <dev@lanza.fr>:

Thanks Harlan for the link, this is what I'm trying to do. =)
With interdependent libs, this becomes a mess anyway... (tried gdk/gtk...)
& thanks René for the video. Very interesting for what will come next.
2015-12-05 18:07 GMT+01:00 Harlan Haskins <harlan@harlanhaskins.com>:
C libraries require you to create modules for them. There's a great guide with examples for importing libjpeg into Swift on GitHub:
https://github.com/apple/swift-package-manager/blob/master/Documentation/SystemModules.md
On Dec 5, 2015, at 8:58 AM, Damien BRUN <dev@lanza.fr> wrote:
Hello Again,
Now that I have a functional Swift installation, I'd like to know if/how I can use C libs ?
How do I import headers & link to the right libs ?
Thanks
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users
_____________________________________________ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users