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-12909] SwiftPM does not use the default library search path for linking system libraries #55355

Open
Lukasa opened this issue May 30, 2020 · 4 comments
Labels

Comments

@Lukasa
Copy link
Contributor

Lukasa commented May 30, 2020

Previous ID SR-12909
Radar rdar://problem/63789281
Original Reporter @Lukasa
Type Bug
Additional Detail from JIRA
Votes 2
Component/s
Labels Bug
Assignee None
Priority Medium

md5: 36b38e09726d2d32e410b2cde5140903

Issue Description:

When using a system library target whose modulemap contains an autolink directive, builds will work but linking will fail. This is appears to be because SwiftPM only searches in the SDK for system library targets, and does not use the linker default search paths. See [this SwiftPM thread| https://forums.swift.org/t/swift-package-manager-linker-flags-and-dependencies/36943] for more details.

@Lukasa
Copy link
Contributor Author

Lukasa commented May 30, 2020

@swift-ci create

@abertelrud
Copy link
Contributor

abertelrud commented Aug 25, 2020

On macOS, iOS, etc, the compiler's built-in SDKs are generally relative to the `-isysroot`. But it looks as if the Clang driver does pass `/usr/local/include` to the compiler, and `-L/usr/local/lib` to the linker if those directories exist in the file system. But `swiftc` does not seem to pass `-L/usr/local/lib` to the linker. So if C code, compiled with `clang`, and Swift code, compiled with `swiftc`, are linked together using the `swiftc` driver, that search path will be missing.

It's not ideal to rely on the compiler driver's behavior here, and anyway, the system library can be at a different path. It seems to me that a straightforward option for when a `.pc` file is not being used would be to provide a way for the system library target to impart header and library search paths to any clients by allowing those paths to be specified in the target itself if a `pkg-config` isn't being used.

@abertelrud
Copy link
Contributor

abertelrud commented Aug 25, 2020

Actually, it's a bit more complicated. Even though the `clang` driver is passing `-L/usr/local/lib`, the fact that it's also passing `-syslibroot` makes that path get prepended by the path of the SDK. So even if SwiftPM passes `-L/usr/local/lib` to a Clang target, it will end up getting redirected to the SDK. The `swiftc` driver also passes `-syslibroot`, so it wouldn't matter whether SwiftPM passes `-L/usr/local/lib` or not, it would end up getting redirected into the SDK if that path exists there.

@swift-ci
Copy link
Collaborator

swift-ci commented Feb 5, 2021

Comment by Lane Schwartz (JIRA)

Some new information: https://forums.swift.org/t/swift-package-manager-linker-flags-and-dependencies/36943/26

TL;DR: On macOS 11.2, if there is a pc file in /usr/local/lib/pkgconfig, swift build can find the library, but XCode still can't.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 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