SwiftProtobuf unable to link on Ubuntu

Has anyone used the SwiftProtobuf module on Linux?

I am able to successfully generate swift classes from my proto file.
However when building, the code compiles but I get a ton of undefined link
references.

I included -Xswiftc -I/home/ed/swift-protobuf/.build/release so the module
is found, but still....

···

------------------------
/home/ed/Documents/prototest/Sources/DataModel.pb.swift:31: error:
undefined reference to '_T013SwiftProtobuf14UnknownStorageVACycfC'
/home/ed/Documents/prototest/Sources/DataModel.pb.swift:31: error:
undefined reference to '_T013SwiftProtobuf14UnknownStorageVACycfC'
/home/ed/Documents/prototest/Sources/DataModel.pb.swift:64: error:
undefined reference to
'_T013SwiftProtobuf14UnknownStorageV8traverseyxz7visitor_tKAA7VisitorRzlF'
/home/ed/Documents/prototest/Sources/DataModel.pb.swift:0: error: undefined
reference to '_T013SwiftProtobuf7MessagePAAE13isInitializedSbfg'

etc...

Does anyone have a simple working example on Ubuntu?

Ubuntu 16.04
Swift 4.0 release

Thanks, Ed

Hi

Has anyone used the SwiftProtobuf module on Linux?
GitHub - apple/swift-protobuf: Plugin and runtime library for using protobuf with Swift

I am able to successfully generate swift classes from my proto file.
However when building, the code compiles but I get a ton of undefined link references.

I included -Xswiftc -I/home/ed/swift-protobuf/.build/release so the module is found, but still….

This should be "-Xlinker” rather than “-Xswiftc”, and also “-l” is for specifying system library names (e.g. "-latomic”). I’m pretty new to this but I think the correct flag is “-L”.
So in the past I have used “-Xlinker -L/path/to/libs”, but I’ve recently read you can actually leave off “-Xlinker” and just have the “-L” bit.

Hope that helps.

- Geordie

···

Am 14.10.2017 um 21:55 schrieb Edward Connell via swift-users <swift-users@swift.org>:

------------------------
/home/ed/Documents/prototest/Sources/DataModel.pb.swift:31: error: undefined reference to '_T013SwiftProtobuf14UnknownStorageVACycfC'
/home/ed/Documents/prototest/Sources/DataModel.pb.swift:31: error: undefined reference to '_T013SwiftProtobuf14UnknownStorageVACycfC'
/home/ed/Documents/prototest/Sources/DataModel.pb.swift:64: error: undefined reference to '_T013SwiftProtobuf14UnknownStorageV8traverseyxz7visitor_tKAA7VisitorRzlF'
/home/ed/Documents/prototest/Sources/DataModel.pb.swift:0: error: undefined reference to '_T013SwiftProtobuf7MessagePAAE13isInitializedSbfg'

etc...

Does anyone have a simple working example on Ubuntu?

Ubuntu 16.04
Swift 4.0 release

Thanks, Ed
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Hi Geordie,
That is actually a capital "I" eye for import
This font make an eye and elle look the same. This is the build line I am
trying to use.

swift build -Xswiftc -I/home/ed/swift-protobuf/.build/release -Xlinker
-L/home/ed/swift-protobuf/.build/release

···

On Sat, Oct 14, 2017 at 1:00 PM, Geordie J <geojay@gmail.com> wrote:

Hi

Am 14.10.2017 um 21:55 schrieb Edward Connell via swift-users < > swift-users@swift.org>:

Has anyone used the SwiftProtobuf module on Linux?
GitHub - apple/swift-protobuf: Plugin and runtime library for using protobuf with Swift

I am able to successfully generate swift classes from my proto file.
However when building, the code compiles but I get a ton of undefined link
references.

I included -Xswiftc -I/home/ed/swift-protobuf/.build/release so the
module is found, but still….

This should be "-Xlinker” rather than “-Xswiftc”, and also “-l” is for
specifying system library names (e.g. "-latomic”). I’m pretty new to this
but I think the correct flag is “-L”.
So in the past I have used “-Xlinker -L/path/to/libs”, but I’ve recently
read you can actually leave off “-Xlinker” and just have the “-L” bit.

Hope that helps.

- Geordie

------------------------
/home/ed/Documents/prototest/Sources/DataModel.pb.swift:31: error:
undefined reference to '_T013SwiftProtobuf14UnknownStorageVACycfC'
/home/ed/Documents/prototest/Sources/DataModel.pb.swift:31: error:
undefined reference to '_T013SwiftProtobuf14UnknownStorageVACycfC'
/home/ed/Documents/prototest/Sources/DataModel.pb.swift:64: error:
undefined reference to '_T013SwiftProtobuf14UnknownStor
ageV8traverseyxz7visitor_tKAA7VisitorRzlF'
/home/ed/Documents/prototest/Sources/DataModel.pb.swift:0: error:
undefined reference to '_T013SwiftProtobuf7MessagePAAE13isInitializedSbfg'

etc...

Does anyone have a simple working example on Ubuntu?

Ubuntu 16.04
Swift 4.0 release

Thanks, Ed
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Hi Edward,

Hi Geordie,
That is actually a capital "I" eye for import
This font make an eye and elle look the same. This is the build line I am trying to use.

My apologies.

swift build -Xswiftc -I/home/ed/swift-protobuf/.build/release -Xlinker -L/home/ed/swift-protobuf/.build/release

Have you considered using Swift Package Manager to add protobuf as a project dependency? Then you wouldn’t have to mess around with command line arguments at all. I haven’t used protobuf yet so can’t help with specifics.

Cheers,
Geordie

···

Am 14.10.2017 um 22:35 schrieb Edward Connell <ewconnell@gmail.com>:

On Sat, Oct 14, 2017 at 1:00 PM, Geordie J <geojay@gmail.com <mailto:geojay@gmail.com>> wrote:
Hi

Am 14.10.2017 um 21:55 schrieb Edward Connell via swift-users <swift-users@swift.org <mailto:swift-users@swift.org>>:

Has anyone used the SwiftProtobuf module on Linux?
https://github.com/apple/swift-protobuf

I am able to successfully generate swift classes from my proto file.
However when building, the code compiles but I get a ton of undefined link references.

I included -Xswiftc -I/home/ed/swift-protobuf/.build/release so the module is found, but still….

This should be "-Xlinker” rather than “-Xswiftc”, and also “-l” is for specifying system library names (e.g. "-latomic”). I’m pretty new to this but I think the correct flag is “-L”.
So in the past I have used “-Xlinker -L/path/to/libs”, but I’ve recently read you can actually leave off “-Xlinker” and just have the “-L” bit.

Hope that helps.

- Geordie

------------------------
/home/ed/Documents/prototest/Sources/DataModel.pb.swift:31: error: undefined reference to '_T013SwiftProtobuf14UnknownStorageVACycfC'
/home/ed/Documents/prototest/Sources/DataModel.pb.swift:31: error: undefined reference to '_T013SwiftProtobuf14UnknownStorageVACycfC'
/home/ed/Documents/prototest/Sources/DataModel.pb.swift:64: error: undefined reference to '_T013SwiftProtobuf14UnknownStorageV8traverseyxz7visitor_tKAA7VisitorRzlF'
/home/ed/Documents/prototest/Sources/DataModel.pb.swift:0: error: undefined reference to '_T013SwiftProtobuf7MessagePAAE13isInitializedSbfg'

etc...

Does anyone have a simple working example on Ubuntu?

Ubuntu 16.04
Swift 4.0 release

Thanks, Ed
_______________________________________________
swift-users mailing list
swift-users@swift.org <mailto:swift-users@swift.org>
https://lists.swift.org/mailman/listinfo/swift-users

I'd strongly recommend using Swift Package Manager to help you here. You need to compile and build protobuf and have that linked into your product at the same time. Since this is what Swift PM works well for that's probably the longer-term supported way forward.

If you're still trying to do this via the command line, I recommend finding where you're compiling the .so for the swift-protobuf code, then using nm and grep to look through that library to confirm whether or not it contains the symbols that your code thinks is missing.

If you have acquired a swift-protobuf binary library from somewhere else, it may not have the Swift code you're looking for, or it may be compiled with a different version of Swift, both of which can affect the names of the symbols being linked. Generally speaking, any _T* symbols are Swift symbols, and that's usually a clue that either they are not present in the libraries you have specified in the command line, or the library you're linking against doesn't have them. Follow the rabbit down the hole and find out which if you are against using Swift PM.

Alex

···

On 14 Oct 2017, at 21:41, Geordie J via swift-users <swift-users@swift.org> wrote:

swift build -Xswiftc -I/home/ed/swift-protobuf/.build/release -Xlinker -L/home/ed/swift-protobuf/.build/release

Have you considered using Swift Package Manager to add protobuf as a project dependency? Then you wouldn’t have to mess around with command line arguments at all. I haven’t used protobuf yet so can’t help with specifics.

Hi Alex,
Yes of course using the Swift PM is what I needed to do. What was I
thinking! ;p
It worked, however SwiftProtobuf 1.0.0 does not build cleanly with Swift
4.0 due to the rework of the Strings API. I hope someone will clean that up
soon.

I appreciate your feedback and time, Ed

···

On Mon, Oct 16, 2017 at 1:42 AM, Alex Blewitt <alblue@apple.com> wrote:

> On 14 Oct 2017, at 21:41, Geordie J via swift-users < > swift-users@swift.org> wrote:
>
>> swift build -Xswiftc -I/home/ed/swift-protobuf/.build/release -Xlinker
-L/home/ed/swift-protobuf/.build/release
>
> Have you considered using Swift Package Manager to add protobuf as a
project dependency? Then you wouldn’t have to mess around with command line
arguments at all. I haven’t used protobuf yet so can’t help with specifics.

I'd strongly recommend using Swift Package Manager to help you here. You
need to compile and build protobuf and have that linked into your product
at the same time. Since this is what Swift PM works well for that's
probably the longer-term supported way forward.

If you're still trying to do this via the command line, I recommend
finding where you're compiling the .so for the swift-protobuf code, then
using nm and grep to look through that library to confirm whether or not it
contains the symbols that your code thinks is missing.

If you have acquired a swift-protobuf binary library from somewhere else,
it may not have the Swift code you're looking for, or it may be compiled
with a different version of Swift, both of which can affect the names of
the symbols being linked. Generally speaking, any _T* symbols are Swift
symbols, and that's usually a clue that either they are not present in the
libraries you have specified in the command line, or the library you're
linking against doesn't have them. Follow the rabbit down the hole and find
out which if you are against using Swift PM.

Alex