C system library enable search on /usr/local/

have a SDL window demo GitHub - 3xau1o/swift-sdl-demo

added library module

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

let package = Package(
    name: "Sample",
    products: [
        .executable(name: "Sample", targets: ["Sample"])
    ],
    targets: [
        .systemLibrary(
            name: "CSDL"
        ),
        .target(
            name: "Sample",
            dependencies: [
                .target(name: "CSDL")
            ]),
    ]
)

then

#include "SDL3/SDL.h"
#include "SDL3/SDL_main.h"
#include "SDL3/SDL_video.h"

had to specify full .so path in modulemap

module CSDL [system] {
    header "libsdl.h"
    link "/usr/local/lib/libSDL3.so"
    export *
}

it works
but want to specify libSDL3 without path like

module CSDL [system] {
    header "libsdl.h"
    link "libSDL3"
    export *
}

however this fails as libraries on /usr/local/ were not found by swift

error: link command failed with exit code 1 (use -v to see invocation)
/usr/bin/ld.gold: error: cannot find -llibSDL3

seems this config did the job

let package = Package(
    name: "Sample",
    products: [],
    targets: [
        .systemLibrary(
            name: "CSDL"
        ),
        .executableTarget(
            name: "Sample",
            dependencies: [
                .target(name: "CSDL")
            ],
            cSettings: [
                .headerSearchPath("usr/local/include", .when(platforms: [.macOS, .linux]))

            ],
            linkerSettings: [
                .linkedLibrary("SDL3")
            ]

        ),
    ]
)
3 Likes

For some reason, the headerSearchPath doesn't work on other paths if not the /usr/* directories. Any reason why?