title: What are the g++ flags to build a true .so/MH_BUNDLE shared library on mac osx (not a dylib)?
body: <p>I'm trying to create a .so on mac osx.   There seems to be a <a href="https://stackoverflow.com/a/2339910/356011">distinction</a> between .so and .dylib types.</p>
  
  <pre><code>$ file  some_real.so
  some_real.so: Mach-O 64-bit bundle x86_64
  </code></pre>
  
  <p>dynamiclib flag produces a dylib as expected</p>
  
  <pre><code>$ g++ -dynamiclib -o libgtest-1.7.0.dylib  [my .o files]
  $ file libgtest-1.7.0.dylib
  libgtest-1.7.0.dylib: Mach-O 64-bit dynamically linked shared library x86_64
  #### ^^^ as expected
  </code></pre>
  
  <p>shared flag is not giving what I want</p>
  
  <pre><code>$ g++ -shared -o libgtest-1.7.0.so  [my .o files]
  $ file libgtest-1.7.0.so
  libgtest-1.7.0.dylib: Mach-O 64-bit dynamically linked shared library x86_64
  #### ^^^ not as expected; wanted bundle x86_64
  </code></pre>
  
  <p>This <a href="https://stackoverflow.com/a/2339910/356011">stackoverflow answer</a> talks about it a bit, and mentions the -fPIC flag.  I added that to the commandline and it still produces a dynlib</p>
  
  <pre><code>$ g++ -shared -fPIC -o libgtest-1.7.0.so  [my .o files]
  $ file libgtest-1.7.0.so
  libgtest-1.7.0.dylib: Mach-O 64-bit dynamically linked shared library x86_64
  #### ^^^ not as expected; wanted bundle x86_64
  </code></pre>
  
  <p>(Why: I need this output to be of the .so/MH_BUNDLE type because I'm trying to create some google tests against something that is already in the .so format and the linker is refusing to link the gtest .dylib and my .so.  )</p>