title: Simple Shared Library MacOS
body: <p>I am trying to create a shared library on the MAC using following the simple example at <a href="https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/CreatingDynamicLibraries.html" rel="nofollow noreferrer">https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/CreatingDynamicLibraries.html</a></p>
  
  <p>I have really dumbed it down to one function to try to get a function exported by clang in a library. My source code is as follows:</p>
  
  <pre><code>#define EXPORT __attribute__((visibility("default")))
  
  EXPORT
  void foo(){
      int x = 1 + 3;  
  }
  </code></pre>
  
  <p>my compile line is </p>
  
  <pre><code>clang -dynamiclib lib.c -current_version 1.0  -compatibility_version 1.0 -fvisibility=hidden -o lib.dylib
  </code></pre>
  
  <p>This compiles fine and produces lib.dylib on my macbook. Now I would expect the nm tool to show my foo() export but the foo method is not exposed</p>
  
  <pre><code>nm -gu lib.dylib
  </code></pre>
  
  <p>returns only</p>
  
  <pre><code>dyld_stub_binder
  </code></pre>
  
  <p>I have been banging my head against this for a day now and it make no sense. Does anyone know what is wrong with this approach.</p>