– I tried looking at static linking in Mac OS X and it seems nearly impossible. Take a look at this http://stackoverflow.com/a/3801032 – I have no idea what that
-staticflag does, but I'm pretty sure that's not how you link to a library. Let me RTFM a bit.
Minutes later...
– I'm gonna have to write this stuff down.
First things first, gcc isn't the default compiler in Mac OS X anymore. Since Xcode 5, the Apple developer toolchain uses clang, and gcc only aliases to clang.
$ gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.3.0
Thread model: posix
NOTE: All the shell outputs here were produced with the default bash on Mac OS X El Capitan 10.11.3 with Xcode 7.2 installed.
man ld:
OPTIONS
Options that control the kind of output
-execute The default. Produce a mach-o main executable that has file type MH_EXECUTE.
-dylib Produce a mach-o shared library that has file type MH_DYLIB.
-bundle Produce a mach-o bundle that has file type MH_BUNDLE.
-dynamic The default. Implied by -dylib, -bundle, or -execute
-static Produces a mach-o file that does not use the dyld. Only used building the kernel.
You, kind sir, are a gem. This tutorial saved me hours of work and provided me a better understanding of how linking on macOS works. Thanks to this I've been able to compile Kiwix command-line tools as standalone executables on macOS. 👍
Here's the closed issue I got to solve: kiwix/kiwix-tools#464