Statically linked binaries on linux


(Joel Hughes) #1

Hi,

I'm attempting to get a statically linked binary and am running into errors.

I'm using Swift 3 Preview 6 on Ubuntu.

Regular _swift build_ and _swift test_ are all running fine.

I can produce a static binary for a simple "hello world" using:

swift build -c release -Xswiftc -static-stdlib

(although I do get error while loading shared libraries: libicui18n.so.55
when running in a basic vm).

However I can't compile a more complicated project. It's only dependency is
Foundation (it uses NSUUID, and JSON) and can't seem to find them.

I get a stream of errors, examples:

Linking ./.build/release/joke
/usr/bin/ld.gold: error: cannot find -lFoundation
...
error: undefined reference to '_TMaC10Foundation6NSUUID'
...
error: undefined reference to
'_TFC10Foundation6NSUUIDCfT10uuidStringSS_GSqS0__'

Any pointers or advice much appreciated.

Thanks

Joel


(Daniel Dunbar) #2

We don't currently build static versions of the other libraries (Foundation, XCTest), or a support process for picking them up.

This is covered by:
  https://bugs.swift.org/browse/SR-648

As you note, it largely works for Swift-only, so this is feasible but we need someone to drive it. Are you interested in working on it?

- Daniel

···

On Sep 1, 2016, at 9:13 AM, Joel Hughes via swift-users <swift-users@swift.org> wrote:

Hi,

I'm attempting to get a statically linked binary and am running into errors.

I'm using Swift 3 Preview 6 on Ubuntu.

Regular _swift build_ and _swift test_ are all running fine.

I can produce a static binary for a simple "hello world" using:

swift build -c release -Xswiftc -static-stdlib

(although I do get error while loading shared libraries: libicui18n.so.55 when running in a basic vm).

However I can't compile a more complicated project. It's only dependency is Foundation (it uses NSUUID, and JSON) and can't seem to find them.

I get a stream of errors, examples:

Linking ./.build/release/joke
/usr/bin/ld.gold: error: cannot find -lFoundation
...
error: undefined reference to '_TMaC10Foundation6NSUUID'
...
error: undefined reference to '_TFC10Foundation6NSUUIDCfT10uuidStringSS_GSqS0__'

Any pointers or advice much appreciated.

Thanks

Joel
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


(Joel Hughes) #3

Hello again,

I've been attempting add to the swift-build script so that Foundation can
be compiled as a static lib. Simialr to

swift/utils/build-script -r --build-swift-static-stdlib --foundation

I'm not familiar with Cmake, ninja and the way the swift is built but have
got the build working. I have a few questions:

Can a libFoundation.a file be compiled from the .o files that are created
while building libFoundation.so?

Is there a guide or recommended tutorial for Cmake and ninja that might be
suitable for a novice, like me?

Are there any documents that give an overview of how the build fits
together and where I should be looking to add functionality? I can't quite
work out how the build script transitions to ninja and clang.

Hope that makes some sense?

Thanks

Joel

···

On 1 September 2016 at 17:13, Joel Hughes <rudenoise@gmail.com> wrote:

Hi,

I'm attempting to get a statically linked binary and am running into
errors.

I'm using Swift 3 Preview 6 on Ubuntu.

Regular _swift build_ and _swift test_ are all running fine.

I can produce a static binary for a simple "hello world" using:

swift build -c release -Xswiftc -static-stdlib

(although I do get error while loading shared libraries: libicui18n.so.55
when running in a basic vm).

However I can't compile a more complicated project. It's only dependency
is Foundation (it uses NSUUID, and JSON) and can't seem to find them.

I get a stream of errors, examples:

Linking ./.build/release/joke
/usr/bin/ld.gold: error: cannot find -lFoundation
...
error: undefined reference to '_TMaC10Foundation6NSUUID'
...
error: undefined reference to '_TFC10Foundation6NSUUIDCfT10uui
dStringSS_GSqS0__'

Any pointers or advice much appreciated.

Thanks

Joel