Skip to content

Instantly share code, notes, and snippets.

@jiacai2050
Forked from loderunner/osx-ld.md
Created March 28, 2022 14:29
Show Gist options
  • Select an option

  • Save jiacai2050/195ea85897815b5280086423d6ec7057 to your computer and use it in GitHub Desktop.

Select an option

Save jiacai2050/195ea85897815b5280086423d6ec7057 to your computer and use it in GitHub Desktop.
potential blog posts

ld – Wading through Mac OS X linker hell

Intro

– 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 -static flag 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.

Reading the fantastic manuals

FANTASTIC!

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.
     
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment