[swift-dev] Issues linking a C library module using swift build

Valentin Radu radu.v.valentin at me.com
Mon Dec 14 18:30:24 CST 2015


Hello all,


I’m having some strange issues on osx when trying to link a C library module. I’ve successfully did this before with another library, however, for some reason this one doesn’t work.
My module map looks like this:

module CFCGI [system] {
    header "/usr/local/include/cfcgi/cfcgi.h"
    link "cfcgi"
    export *
}

And the output:

swift build
Compiling Swift Module 'April' (1 sources)
Linking Executable:  .build/debug/April
Undefined symbols for architecture x86_64:
  "_cfcgi_create", referenced from:
      _main in main.swift.o
  "_cfcgi_free", referenced from:
      _main in main.swift.o
  "_cfcgi_start_and_wait", referenced from:
      _main in main.swift.o
ld: symbol(s) not found for architecture x86_64


It looks like the linker ignores the `link "cfcgi”` part. 
I tried lots of things but failed to find the reason behind this. I’m starting to think this might be related to this paragraph in the clang docs:

"Automatic linking with the link directive is not yet widely implemented, because it requires support from both the object file format and the linker. The notion is similar to Microsoft Visual Studio’s #pragma comment(lib…).”

Unfortunately I find it a little vague and I can’t know for sure if it applies here.

So far, this is what I know for sure:
- libcfcgi.a is in /usr/local/lib and it’s compiled for x86_64
- libcfcgi.a contains the above mentioned symbols, tested it with nm and linked it in a small C program 
- I’m on osx and build with the swift-2.2-SNAPSHOT-2015-12-01-a toolchain


Any input on this would be greatly appreciated!

Valentin Radu





-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20151215/d4aa2c7c/attachment.html>


More information about the swift-dev mailing list