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-2465] [SwiftPM] Xcode project cannot use C language target with custom module map #5231

Closed
swift-ci opened this issue Aug 24, 2016 · 5 comments
Labels

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-2465
Radar rdar://problem/28038845
Original Reporter tannernelson (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 1
Component/s Package Manager
Labels Bug, GeneratedXcodeProject
Assignee tannernelson (JIRA)
Priority Medium

md5: 0df614a075251ed651eb1426b3eb8b78

is duplicated by:

  • SR-2215 Error linking C wrapper module in Kitura when using generated Xcode project

Issue Description:

Xcode 8 beta 6 with 08-23

COpenSSL from Perfect (https://github.com/PerfectlySoft/Perfect-COpenSSL) has the following module map:

module COpenSSL {
    header "openssl.h"
    link "COpenSSL"
}

This builds great on macOS and Linux command lines.

But when an Xcode project is generated, I get this error:

ld: library not found for -lCOpenSSL for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

This fixes Xcode:

Under Project > Build Settings > Library Search Paths, add:

$(PROJECT_DIR)/**

Changing the module map to create a framework also fixes Xcode without the need for the search path hack. But this change breaks macOS and Linux command line which seem to rely on shared libs.

module COpenSSL {
    header "openssl.h"
    link framework "COpenSSL"
}

The change is just adding `framework` to the `link "COpenSSL"` line.

With `framework` added, here are the build errors for macOS and Linux (Xcode works)

Ubuntu 14.04

Compile Swift Module 'HTTPExample' (2 sources)
Linking ./.build/debug/SMTPExample
/usr/bin/ld.gold: fatal error: -f/--auxiliary may not be used without -shared
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)
<unknown>:0: error: build had 1 command failures
error: exit(1): /home/qutheory/.swiftenv/versions/DEVELOPMENT-SNAPSHOT-2016-08-23-a/usr/bin/swift-build-tool -f /home/qutheory/vapor/engine/.build/debug.yaml
qutheory@qutheory-2:~/vapor/engine$ 

macOS El Cap

Linking ./.build/debug/HTTPExample
ld: framework not found COpenSSL for architecture x86_64
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
ld: framework not found COpenSSL for architecture x86_64
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: build had 2 command failures
error: exit(1): /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-08-23-a.xctoolchain/usr/bin/swift-build-tool -f /Users/tanner/Developer/vapor/engine/.build/debug.yaml
Gertrude:engine tanner$ 

TL;DR

`link ...` only works for command lines.
`link framework ...` only works for Xcode.

@ddunbar
Copy link
Member

ddunbar commented Aug 24, 2016

@aciidb0mb3r do you know what this is?

@ankitspd
Copy link
Member

ankitspd commented Sep 2, 2016

The problem is that we generate framework targets in Xcode project so the user provided modulemap fails to link that library because there isn't one.

After some discussion a possible solution right now is generating Xcode projects with a shell script build phase that create symlinks to binaries inside frameworks named lib<library_name>.dylib and add the path to symlink directly in library search path so linker can find and link it.

@ankitspd
Copy link
Member

ankitspd commented Sep 7, 2016

Fixed in #630

@swift-ci
Copy link
Contributor Author

Comment by tanner0101 (JIRA)

I'm still getting this same error with Swift 3.0. Was it not included in the release?

@ddunbar
Copy link
Member

ddunbar commented Sep 20, 2016

IIRC this was only fixed after the branch was finalized.

@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
This issue was closed.
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