SPM using wrong name for linked library on linux?

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.

1 Like