felix91gr / Csdjournal

A Swift wrapper around Linux's `systemd-sdjournal` header
0 stars 1 forks source link

Multiple definition of 'csd_journal_print' #1

Closed RLovelett closed 6 years ago

RLovelett commented 6 years ago
...
Linking ./.build/x86_64-unknown-linux/debug/langserver-swift
/usr/bin/ld.gold: error: /home/rlovelett/Source/langserver-swift/.build/x86_64-unknown-linux/debug/LanguageServer.build/main.swift.o: multiple definition of 'csd_journal_print'
/usr/bin/ld.gold: /home/rlovelett/Source/langserver-swift/.build/x86_64-unknown-linux/debug/BaseProtocol.build/Types/Request.swift.o: previous definition here
clang-6.0: 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)
error: terminated(1): /home/rlovelett/Source/swift-source/rlovelett-installation/usr/bin/swift-build-tool -f /home/rlovelett/Source/langserver-swift/.build/debug.yaml main output:

You get this error if you have two source files, e.g., main.swift and Request.swift, that both import CSDJournal and make reference to csd_journal_print.

I'm 99% sure this is due to the fact that shim.h is not just a header file but also includes the function implementation (which is why it fails at link time).

RLovelett commented 6 years ago

My bet is that you'll need to implement this module something like this: Wrapping C Code Within a Single Swift Package to get rid of this error. Edit: Package Manager C Language Target Support

felix91gr commented 6 years ago

Oh, good catch! Lemme see, I think there's another option that I've seen other C wrappers use. I'm going to upload a new release that probably fixes this.

felix91gr commented 6 years ago

Okay, here it is: https://github.com/felix91gr/Csdjournal/releases/tag/1.0.2 How's working for you?

Edit: fwiw, what I added is an #include guard

felix91gr commented 6 years ago

Hmm, I'm testing it here and it doesn't work: it still says I have multiple definitions.

I'll try with what you said :)

felix91gr commented 6 years ago

The problem with that post is that it shouldn't work for System Packages (like systemd). The supported way of importing C System Packages into Swift is by using a *.h file in the root directory (basically what I did).

Maybe we can wrap this wrapper in a Swift package? Is that too crazy?

felix91gr commented 6 years ago

Okay, nevermind what I said. I thoroughly read IBM's implementation of their wrapper for CCurl, and after testing the usage of static inline I found out that it fixes the double definition problem.

Tell me if it now works for you: https://github.com/felix91gr/Csdjournal/releases/tag/1.2.0

RLovelett commented 6 years ago

1.2.0 does it. Great job! Now once you get this included in Tracelog we'll be pretty close to a functional cross-platform logger. :+1: