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-11947] SPM using wrong name for linked library on linux? #4636

Open
swift-ci opened this issue Dec 12, 2019 · 1 comment
Open

[SR-11947] SPM using wrong name for linked library on linux? #4636

swift-ci opened this issue Dec 12, 2019 · 1 comment
Labels

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-11947
Radar rdar://problem/57888489
Original Reporter rmann (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Package Manager
Labels Bug
Assignee None
Priority Medium

md5: 6cd95e507db6ba57eec9c2432d238bc2

Issue Description:

From my post on the forums: https://forums.swift.org/t/spm-using-wrong-name-for-linked-library-on-linux/31589

I made a ton of progress getting my Swift/SDL app working. Builds fine under SPM and Xcode on macOS, but on Linux I'm running into some issues. In particular, the way it's trying to link SDL2_ttf is wrong. That is, it should be linking against libSDL2_ttf, but instead it’s trying to link against libSDL2TTF. I can't actually find that string anywhere in my code, and pkg-config gives this:

$ pkg-config --cflags --libs sdl2_ttf
-D_REENTRANT -I/usr/local/include/SDL2 -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux -L/usr/local/lib -lSDL2_ttf -Wl,~~rpath,/usr/local/lib -Wl,~~-enable-new-dtags -lSDL2

But when Swift goes to link, it does:

$ swift build --verbose
lsb_release -r
uname
pkg-config --variable pc_path pkg-config
'CSDL2TTF' sdl2_ttf.pc: warning: non whitelisted flag(s): -D_REENTRANT, -Wl,~~rpath,/usr/local/lib, -Wl,~~-enable-new-dtags
'CSDL2' sdl2.pc: warning: non whitelisted flag(s): -D_REENTRANT, -Wl,~~rpath,/usr/local/lib, -Wl,~~-enable-new-dtags
/usr/local/swift/versions/5.1.1-armv7-DebianBuster/usr/bin/swiftc -sdk / -L/usr/local/lib -lSDL2_ttf -L/usr/local/lib -lSDL2 -L/usr/local/lib -lSDL2 -g -L /home/rmann/InfoDisplay/.build/armv7-unknown-linux-gnueabihf/debug -o /home/rmann/InfoDisplay/.build/armv7-unknown-linux-gnueabihf/debug/InfoDisplay -module-name InfoDisplay -emit-executable -Xlinker '-rpath=$ORIGIN' @/home/rmann/InfoDisplay/.build/armv7-unknown-linux-gnueabihf/debug/InfoDisplay.product/Objects.LinkFileList -target armv7-unknown-linux-gnueabihf -L /usr/local/swift/versions/5.1.1-armv7-DebianBuster/usr/lib
/usr/bin/ld.gold: error: cannot find -lSDL2TTF
/usr/bin/ld.gold: error: cannot find -lSDL2TTF
/usr/bin/ld.gold: error: cannot find -lSDL2TTF
/usr/bin/ld.gold: error: cannot find -lSDL2TTF
/usr/bin/ld.gold: error: cannot find -lSDL2TTF
/usr/bin/ld.gold: error: cannot find -lSDL2TTF
/usr/bin/ld.gold: error: cannot find -lSDL2TTF
/usr/bin/ld.gold: error: cannot find -lSDL2TTF
/usr/bin/ld.gold: error: cannot find -lSDL2TTF
/usr/bin/ld.gold: error: cannot find -lSDL2TTF
/usr/bin/ld.gold: error: cannot find -lSDL2TTF
/usr/bin/ld.gold: error: cannot find -lSDL2TTF
/usr/bin/ld.gold: error: cannot find -lSDL2TTF
/usr/bin/ld.gold: error: cannot find -lSDL2TTF
/usr/bin/ld.gold: error: cannot find -lSDL2TTF
/usr/bin/ld.gold: error: cannot find -lSDL2TTF
/usr/bin/ld.gold: error: cannot find -lSDL2TTF
/usr/bin/ld.gold: error: cannot find -lSDL2TTF
/usr/bin/ld.gold: error: cannot find -lSDL2TTF
/usr/bin/ld.gold: error: cannot find -lSDL2TTF
/usr/bin/ld.gold: error: cannot find -lSDL2TTF
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)

You can see more details here.

Here’s my Package.swift for the library:

// swift-tools-version:5.0
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription

let package = Package(
    name: "SDL",
    products: [
        .library(
            name: "SDL",
            targets: ["SDL"]),
        ],
    targets: [
        .target(
            name: "SDL",
            dependencies: ["CSDL2", "CSDL2TTF"]),
        .systemLibrary(
            name: "CSDL2",
            pkgConfig: "sdl2",
            providers: [
                .brew(["sdl2"]),
                .apt(["libsdl2-dev"])
            ]),
        .systemLibrary(
            name: "CSDL2TTF",
            pkgConfig: "sdl2_ttf",
            providers: [
                .brew(["sdl2_ttf"]),
                .apt(["libsdl2-ttf-dev"])
            ]),
        ],
    swiftLanguageVersions: [.v5]
)

I can’t figure out why it’s trying to do that. It’s finding SDL2 just fine.

@beccadax
Copy link
Contributor

@swift-ci create

@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