Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-8715] swift build fails when using pkg-config to link to gtk3 #4894

Open
swift-ci opened this issue Sep 7, 2018 · 2 comments
Open

[SR-8715] swift build fails when using pkg-config to link to gtk3 #4894

swift-ci opened this issue Sep 7, 2018 · 2 comments
Labels

Comments

@swift-ci
Copy link
Contributor

swift-ci commented Sep 7, 2018

Previous ID SR-8715
Radar rdar://problem/44307765
Original Reporter TaborKelly (JIRA User)
Type Bug

Attachment: Download

Environment
  • macOS 10.13.6

  • Apple Swift version 4.1.2 (swiftlang-902.0.54 clang-902.0.39.2)

  • XCode 9.4.1 (9F2000)

  • Homebrew 1.7.3

  • gtk3, from Homebrew: gtk+3: stable 3.22.30 (bottled)

Additional Detail from JIRA
Votes 0
Component/s Package Manager
Labels Bug
Assignee None
Priority Medium

md5: f69a9e1e0a1b22549844a804414d7868

Issue Description:

I am trying to link to gtk3 with swift 4.1.2 but it is failing to find the headers (that is, it fails before the link stage). I have two repos on github that demonstrate the issue:

  • CGtk3 - here pkgConfig is setup just like the official documentation.

  • Gtk3 - just a Hello World importing CGtk3

When I try to build Gtk3 from above, I get the following error:

$ swift build
Fetching git@github.com:TaborKelly/CGtk3.git
Cloning git@github.com:TaborKelly/CGtk3.git
Resolving git@github.com:TaborKelly/CGtk3.git at 0.1.0
Compile Swift Module 'Gtk3' (1 sources)
<module-includes>:1:9: note: in file included from <module-includes>:1:
#import "shim.h"
        ^
/Users/tabor.kelly/work/Gtk3/.build/checkouts/CGtk3.git-1657053074184707870/shim.h:4:10: error: 'gtk/gtk.h' file not found
#include <gtk/gtk.h>
         ^
/Users/tabor.kelly/work/Gtk3/Sources/main.swift:3:8: error: could not build Objective-C module 'CGtk3'
import CGtk3
       ^
error: terminated(1): /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build-tool -f /Users/tabor.kelly/work/Gtk3/.build/debug.yaml main output:

Please note that pkg-config does know how to find these headers:

$ pkg-config gtk+-3.0 --cflags
-D_REENTRANT -I/usr/local/Cellar/gtk+3/3.22.30/include/gtk-3.0 -I/usr/local/Cellar/glib/2.58.0/include/gio-unix-2.0/ -I/usr/local/Cellar/cairo/1.14.12/include/cairo -I/usr/local/Cellar/libepoxy/1.5.2/include -I/usr/local/Cellar/pango/1.42.4/include/pango-1.0 -I/usr/local/Cellar/harfbuzz/1.8.8/include/harfbuzz -I/usr/local/Cellar/graphite2/1.3.12/include -I/usr/local/Cellar/pango/1.42.4/include/pango-1.0 -I/usr/local/Cellar/fribidi/1.0.5/include/fribidi -I/usr/local/Cellar/atk/2.28.1_2/include/atk-1.0 -I/usr/local/Cellar/cairo/1.14.12/include/cairo -I/usr/local/Cellar/pixman/0.34.0_1/include/pixman-1 -I/usr/local/Cellar/fontconfig/2.13.1/include -I/usr/local/opt/freetype/include/freetype2 -I/usr/local/Cellar/libpng/1.6.35/include/libpng16 -I/usr/local/Cellar/gdk-pixbuf/2.36.12/include/gdk-pixbuf-2.0 -I/usr/local/Cellar/libpng/1.6.35/include/libpng16 -I/usr/local/Cellar/glib/2.58.0/include/glib-2.0 -I/usr/local/Cellar/glib/2.58.0/lib/glib-2.0/include -I/usr/local/opt/gettext/include -I/usr/local/Cellar/pcre/8.42/include

Specifically, gtk/gtk.h is located in /usr/local/Cellar/gtk+3/3.22.30/include/gtk-3.0.

Additionally, have told CGtk3 to use the pkg-config information for gtk+-3.0:

import PackageDescription

let package = Package(
    name: "CGtk3",
    pkgConfig: "gtk+-3.0",
    providers: [
        .Brew("gtk+3"),
        .Apt("gtk3")
    ]
)

Please let me know if there is any other information which I can provide.

@ankitspd
Copy link
Member

@swift-ci create

@ankitspd
Copy link
Member

This is happening because gtk has a dependency on glib which is adding `-Wl,-framework -Wl,CoreFoundation` linker flags. SwiftPM doesn't know about these flags and emits a warning about non-whitelisted flags. You're not seeing the warnings because there was a bug in older swiftpm that caused it to not emit these warnings. The solution here to add -Wl to the whitelist. Also, please use the latest version of the manifest API. I am attaching the equivalent package with Swift 4.2 manifest. As a workaround, you can remove the -Wl flags from glib's pkgConfig file.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants