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-151] Stdlib not being linked on swift build #42773
Comments
Spot anything missing @ddunbar? |
Unfortunately I am experiencing the same issue on my Mac.. 'swift --version' prints the following: Apple Swift version 2.2-dev (LLVM 7bae82deaa, Clang 53d04af5ce, Swift 5995ef2) In my case types like CollectionType are not defined due to the log. So the stdlib is not linked like in kiliankoe (JIRA User)s problem.. On Linux it's working well, but on OS X even the Dealer example project from Github does not compile out of the box. |
Gentle ping @ddunbar. Could it be the PM’s internal SDK selection has gone wrong, or is this a higher level? |
What OS version on you on? What is your linker version? (`ld -v`) |
Can you also include the output of: |
Comment by Kilian Koeltzsch (JIRA) Hi, I'm on OS X 10.11.2 (15C50). The output from `ld -v` is: @(#)PROGRAM:ld PROJECT:ld64-253.9 And the output of the verbose version from before: Apple Swift version 2.2-dev (LLVM 46be9ff861, Clang 4deb154edc, Swift 778f829) |
I don't yet have a good clue here... I do notice you are on Xcode 7.0, but I wouldn't actually expect that to fail. If possible, it may be worth upgrading to the latest Xcode and trying that, it would at least be valuable information to know if it fails in the same manner. |
Comment by Kilian Koeltzsch (JIRA) For what it's worth, I've made sure to install the most current version of Xcode, choosing it via xcode-select and have also installed the latest dev snapshots of the Swift packages unfortunately to no avail. The output stays pretty much the same. |
What’s your `PATH`? |
Comment by Kilian Koeltzsch (JIRA) `/Users/kilian/.rvm/gems/ruby-2.2.3/bin:/Users/kilian/.rvm/gems/ruby-2.2.3@global/bin:/Users/kilian/.rvm/rubies/ruby-2.2.3/bin:/Users/kilian/.rvm/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/MacGPG2/bin:/Library/TeX/texbin:/Users/kilian/scripts:/Users/kilian/develop/go/bin` I've aliased the swift tools explicitly like this: But throwing the entire directory into my path via `export PATH="/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin:$PATH"` doesn't make a difference it seems. |
I just tried on a clean install of 10.11 and it built without issue. I tried with Xcode 7.0, 7.1, and 7.2, all work ok. Can you try: If that doesn't work, we are going to need to dig in on exactly why the mechanism that should be working isn't here. The way that this mechanism is supposed to work is as follows: 1. In main.o, there should be an auto linking directive telling ld to link swiftCore. You can verify whether or not that exists by running: That should come up with output like: Link command 5 2. Try rerunning the swiftc link invocation (as reported by swift build -v) and add an explicit -lswiftCore. Does that resolve the issue? 3. Finally, you can also add "-t -v" to the linker invocation to see exactly what files the linker is including. That may illuminate the problem... |
Awesome![]( 'env -i PATH=/bin:/usr/bin /Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin/swift build' is working for me) Actually it's working as it should since I executed this command... I changed the PATH variable a few minutes ago, maybe this change did it? |
Comment by Kilian Koeltzsch (JIRA) `env -i PATH=/bin:/usr/bin /Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin/swift build` seems to have no effect. Interestingly enough `env -i PATH=/bin:/usr/bin echo $PATH` or `PATH=/bin:/usr/bin echo $PATH` similarly just output my normal PATH. I've manually exported PATH to be set to `/bin:/usr/bin` and then ran swift build again running into the same issues as before. Regarding 1: Regarding 2: Regarding 3: Thanks for all the help along the way by the way![]( I really appreciate it) |
@BenchR267 Most likely the change to PATH did resolve the issue kiliankoe (JIRA User) What you showed for env -i is expected. What the "-i" flag does is that it erases all of the other environment variables other than the ones that are set. What I was trying to probe for was whether it could be the case that some other environment variable was what was causing the problem (e.g., various tools on our platform look at SDKROOT and TOOLCHAINS, and I thought it might be possible that if you had some of those set it was introducing the issue). The command I expected you to add the flags to was the last command to be output (which is the one invoking the linker), not the first. @jckarter Do you have any idea what might be going on here? Can you tell from the mangling if we are getting the wrong compiler at some point, or something? |
It's a possibility. There was a mangling change after Xcode 7.0 (or maybe 7.1, I forget), so if you're building with open-source Swift but linking to the stdlib from the SDK, those symbols might be missing. |
Comment by Eli Perkins (JIRA) For what it's worth, my environment is also replicating this issue. $ git clone https://github.com/apple/example-package-dealer.git
Cloning into 'example-package-dealer'...
remote: Counting objects: 18, done.
remote: Total 18 (delta 0), reused 0 (delta 0), pack-reused 18
Unpacking objects: 100% (18/18), done.
Checking connectivity... done.
$ cd example-package-dealer
$ swift build
Compiling Swift Module 'FisherYates' (1 sources)
Linking Library: .build/debug/FisherYates.a
Compiling Swift Module 'PlayingCard' (3 sources)
Linking Library: .build/debug/PlayingCard.a
Compiling Swift Module 'DeckOfPlayingCards' (1 sources)
Linking Library: .build/debug/DeckOfPlayingCards.a
Compiling Swift Module 'Dealer' (1 sources)
Linking Executable: .build/debug/Dealer
Undefined symbols for architecture x86_64:
"__TFEsPs14CollectionTypeg7isEmptySb", referenced from:
__TFV18DeckOfPlayingCards4Deck4dealfT_GSqV11PlayingCard11PlayingCard_ in DeckOfPlayingCards.a(Deck.swift.o)
"__TFSSCfT21_builtinStringLiteralBp8byteSizeBw7isASCIIBi1__SS", referenced from:
_main in main.swift.o
__TFV11PlayingCard11PlayingCardg11descriptionSS in PlayingCard.a(PlayingCard.swift.o)
__TFO11PlayingCard4Rankg11descriptionSS in PlayingCard.a(Rank.swift.o)
__TFO11PlayingCard4SuitCfT8rawValueSS_GSqS0__ in PlayingCard.a(Suit.swift.o)
__TFO11PlayingCard4Suitg8rawValueSS in PlayingCard.a(Suit.swift.o)
"__TFSSCfT26_builtinUTF16StringLiteralBp17numberOfCodeUnitsBw_SS", referenced from:
__TFO11PlayingCard4Suitg11descriptionSS in PlayingCard.a(Suit.swift.o)
"__TFSSCfT26stringInterpolationSegmentSS_SS", referenced from:
__TFV11PlayingCard11PlayingCardg11descriptionSS in PlayingCard.a(PlayingCard.swift.o)
__TFO11PlayingCard4Rankg11descriptionSS in PlayingCard.a(Rank.swift.o)
...
__TTWV11PlayingCard11PlayingCards10ComparableS_ZFS1_oi2gefTxx_Sb in PlayingCard.a(PlayingCard.swift.o)
__TTWO11PlayingCard4Ranks10ComparableS_ZFS1_oi2gefTxx_Sb in PlayingCard.a(Rank.swift.o)
__TTWO11PlayingCard4Suits10ComparableS_ZFS1_oi2gefTxx_Sb in PlayingCard.a(Suit.swift.o)
"__TZFsoi2leuRxs10ComparablerFTxx_Sb", referenced from:
__TTWV11PlayingCard11PlayingCards10ComparableS_ZFS1_oi2lefTxx_Sb in PlayingCard.a(PlayingCard.swift.o)
__TTWO11PlayingCard4Ranks10ComparableS_ZFS1_oi2lefTxx_Sb in PlayingCard.a(Rank.swift.o)
__TTWO11PlayingCard4Suits10ComparableS_ZFS1_oi2lefTxx_Sb in PlayingCard.a(Suit.swift.o)
"__TZvOs7Process11_unsafeArgvGSpGSpVs4Int8__", referenced from:
_main in main.swift.o
"__TZvOs7Process5_argcVs5Int32", referenced from:
_main in main.swift.o
"_globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_func5", referenced from:
_main in main.swift.o
"_globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_token5", referenced from:
_main in main.swift.o
ld: symbol(s) not found for architecture x86_64
<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): ["/Library/Developer/Toolchains/swift-2.2-SNAPSHOT-2016-01-11-a.xctoolchain/usr/bin/swift-build-tool", "-f", "/Users/elperkins/src/example-package-dealer/.build/debug/Dealer.o/llbuild.yaml"] And same using `env -i` env -i PATH=/bin:/usr/bin /Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin/swift build
Compiling Swift Module 'FisherYates' (1 sources)
Linking Library: .build/debug/FisherYates.a
Compiling Swift Module 'PlayingCard' (3 sources)
Linking Library: .build/debug/PlayingCard.a
Compiling Swift Module 'DeckOfPlayingCards' (1 sources)
Linking Library: .build/debug/DeckOfPlayingCards.a
Compiling Swift Module 'Dealer' (1 sources)
Linking Executable: .build/debug/Dealer
Undefined symbols for architecture x86_64:
"__TFEsPs14CollectionTypeg7isEmptySb", referenced from:
__TFV18DeckOfPlayingCards4Deck4dealfT_GSqV11PlayingCard11PlayingCard_ in DeckOfPlayingCards.a(Deck.swift.o)
"__TFSSCfT21_builtinStringLiteralBp8byteSizeBw7isASCIIBi1__SS", referenced from:
_main in main.swift.o
__TFV11PlayingCard11PlayingCardg11descriptionSS in PlayingCard.a(PlayingCard.swift.o)
__TFO11PlayingCard4Rankg11descriptionSS in PlayingCard.a(Rank.swift.o)
__TFO11PlayingCard4SuitCfT8rawValueSS_GSqS0__ in PlayingCard.a(Suit.swift.o)
__TFO11PlayingCard4Suitg8rawValueSS in PlayingCard.a(Suit.swift.o)
"__TFSSCfT26_builtinUTF16StringLiteralBp17numberOfCodeUnitsBw_SS", referenced from:
__TFO11PlayingCard4Suitg11descriptionSS in PlayingCard.a(Suit.swift.o)
...
_main in main.swift.o
"__TZvOs7Process5_argcVs5Int32", referenced from:
_main in main.swift.o
"_globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_func5", referenced from:
_main in main.swift.o
"_globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_token5", referenced from:
_main in main.swift.o
ld: symbol(s) not found for architecture x86_64
<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): ["/Library/Developer/Toolchains/swift-2.2-SNAPSHOT-2016-01-06-a.xctoolchain/usr/bin/swift-build-tool", "-f", "/Users/elperkins/src/example-package-dealer/.build/debug/Dealer.o/llbuild.yaml"] $ otool -lV .build/debug/Dealer.o/main.swift.o
...
Load command 3
cmd LC_DYSYMTAB
...
Load command 4
cmd LC_LINKER_OPTION
cmdsize 24
count 1
string #​1 -lswiftCore
Load command 5
cmd LC_LINKER_OPTION
cmdsize 24
count 1
string #​1 -lobjc $ swift --version
Apple Swift version 2.2-dev (LLVM 3ebdbb2c7e, Clang f66c5bb67b, Swift 42591f7cba)
Target: x86_64-apple-macosx10.9
$ xcodebuild -version
Xcode 7.3
Build version 7D111g OS X 10.11.4 Beta (15E27e) If there's any more context I can provide, I'd be glad to! |
Comment by Stepan Hruda (JIRA) Happens to me as well.
Happy to help with additional investigation on my environment. |
@belkadan knows the driver better than me. Does `-L` help at all? |
Comment by Loïc Dalbin (JIRA) I have the same problem, but if I reuse the same command removing the ❯ swift build -vv
...
/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-02-08-a.xctoolchain/usr/bin/swift-build-tool -v -f /Users/loic/Temp/example-package-dealer/.build/debug/Dealer.o/llbuild.yaml
/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-02-08-a.xctoolchain/usr/bin/swiftc -o /Users/loic/Temp/example-package-dealer/.build/debug/Dealer /Users/loic/Temp/example-package-dealer/.build/debug/Dealer.o/main.swift.o -target x86_64-apple-macosx10.10 -Xlinker -all_load -g -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk /Users/loic/Temp/example-package-dealer/.build/debug/DeckOfPlayingCards.a /Users/loic/Temp/example-package-dealer/.build/debug/PlayingCard.a /Users/loic/Temp/example-package-dealer/.build/debug/FisherYates.a -L/usr/local/lib
Undefined symbols for architecture x86_64:
"__TFEsPs14CollectionTypeg7isEmptySb", referenced from:
__TFV18DeckOfPlayingCards4Deck4dealfT_GSqV11PlayingCard11PlayingCard_ in DeckOfPlayingCards.a(Deck.swift.o)
..... Full log : https://gist.github.com/dalbin/45d75965b8ed28a47e10 |
dalbin (JIRA User) interesting. Please note: the latest snapshot doesn't add However, I wonder what is going on here. |
Comment by Loïc Dalbin (JIRA) Thank you, I have upgraded and now it's works perfectly. |
Comment by Eli Perkins (JIRA) Ah![]( Interesting. Exhibited the same thing as dalbin (JIRA User), upgrading to |
Awesome, it's working! |
Comment by Kilian Koeltzsch (JIRA) Same here, latest version as of now seems to be working just fine on my end as well. Thank you!! |
Comment by Loïc Dalbin (JIRA) By the way, I can't build https://github.com/IBM-Swift/Kitura which link to libraries in /usr/local/lib |
You can add Could one of your for whom it is fixed list your |
Comment by Kilian Koeltzsch (JIRA) Here's a listing of the contents of my `/usr/local/lib` directory: http://hastebin.com/kenulimuju.avrasm |
And there we have it: libswiftAppKit.dylib
libswiftCore.dylib
libswiftCoreData.dylib
libswiftCoreGraphics.dylib
libswiftCoreImage.dylib
libswiftDarwin.dylib
libswiftDispatch.dylib
libswiftFoundation.dylib
libswiftObjectiveC.dylib I guess this is the Homebrew installed swift? |
Comment by Kilian Koeltzsch (JIRA) If I'm not entirely mistaken I've never installed swift itself through Homebrew (definitely not currently), but I have done so with several tools built with swift (e.g. swiftgen, swiftlint, chswift, alcatraz, etc.). Not sure if that makes a difference though or not. |
Comment by Stepan Hruda (JIRA) @mxcl you are correct, sir:
|
I am having a similar issue but only during `swift test` |
Attachment: Download
Environment
OS X 10.11.1
Apple Swift version 2.2-dev (LLVM 46be9ff861, Clang 4deb154edc, Swift 778f829) Target: x86_64-apple-macosx10.9.
Additional Detail from JIRA
md5: f9e35afc3998fdc2ff1af4f08db14241
Issue Description:
Hi,
as pushed over swift-users@ previously, I'm currently experiencing an issue where `swift build` apparently fails to link the standard library.
The project being built here is just a minimal hello-world example with nothing but a print() statement. Everything seems to run just fine in the REPL.
Here's the verbose output when trying to build:
```
/Library/Developer/Toolchains/swift-2.2-SNAPSHOT-2015-12-01-a.xctoolchain/usr/bin/swiftc -module-name foo -incremental -emit-dependencies -emit-module -emit-module-path /Users/kilian/Desktop/foo/.build/debug/foo.swiftmodule -output-file-map /Users/kilian/Desktop/foo/.build/debug/foo.o/foo/output-file-map.json -c /Users/kilian/Desktop/foo/Sources/main.swift -I /Users/kilian/Desktop/foo/.build/debug -j8 -Onone -g -target x86_64-apple-macosx10.10 -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -I /usr/local/include
/Library/Developer/Toolchains/swift-2.2-SNAPSHOT-2015-12-01-a.xctoolchain/usr/bin/swiftc -o /Users/kilian/Desktop/foo/.build/debug/foo /Users/kilian/Desktop/foo/.build/debug/foo.o/Sources/main.swift.o -Xlinker -all_load -target x86_64-apple-macosx10.10 -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -L/usr/local/lib
Undefined symbols for architecture x86_64:
"TFSSCfT21_builtinStringLiteralBp8byteSizeBw7isASCIIBi1_SS", referenced from:
_main in main.swift.o
"TFs5printFTGSaP9separatorSS10terminatorSS_T", referenced from:
_main in main.swift.o
"TIFs5printFTGSaP9separatorSS10terminatorSS_T_A0", referenced from:
_main in main.swift.o
"TIFs5printFTGSaP9separatorSS10terminatorSS_T_A1", referenced from:
_main in main.swift.o
"__TMSS", referenced from:
_main in main.swift.o
"TTSg5PTFs27_allocateUninitializedArrayurFBwTGSax_Bp*", referenced from:
_main in main.swift.o
"TZvOs7Process11_unsafeArgvGSpGSpVs4Int8*_", referenced from:
_main in main.swift.o
"__TZvOs7Process5_argcVs5Int32", referenced from:
_main in main.swift.o
"_globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_func5", referenced from:
_main in main.swift.o
"_globalinit_33_1BDF70FFC18749BAB495A73B459ED2F0_token5", referenced from:
_main in main.swift.o
ld: symbol(s) not found for architecture x86_64
<unknown>:0: error: build had 1 command failures
swift-build: exit(1): ["/Library/Developer/Toolchains/swift-2.2-SNAPSHOT-2015-12-01-a.xctoolchain/usr/bin/swift-build-tool", "-v", "-f", "/Users/kilian/Desktop/foo/.build/debug/foo.o/llbuild.yaml"]
```
The text was updated successfully, but these errors were encountered: