title: Haskell/cabal: Possible to link to .so file on macos?
body: <p>On a mac, I've done <code>brew install freetds</code>, which gives me a file <code>libtdsodbc.so</code>. Now I try to link to that by putting the path to it in <code>extra-lib-dirs</code> in my .cabal, but I get </p>
  
  <pre><code>* Missing (or bad) C library: tdsodbc
  This problem can usually be solved by installing the system package that
  provides this library (you may need the "-dev" version). If the library is
  already installed but in a non-standard location then you can use the flags
  --extra-include-dirs= and --extra-lib-dirs= to specify where it is.If the
  library file does exist, it may contain errors that are caught by the C
  compiler at the preprocessing stage. In this case you can re-run configure
  with the verbosity flag -v3 to see the error messages.
  
  </code></pre>
  
  <p>Doing <code>stack build --verbose</code> shows me the command that fails was cabal configure, so I run that again with <code>-v3</code> appended, which tells me:</p>
  
  <pre><code>/usr/bin/gcc -fno-stack-protector /var/folders/bq/4xy9knvx413dwltf9c6ngvvm0000gt/T/29185-4.c -o /var/folders/bq/4xy9knvx413dwltf9c6ngvvm
  0000gt/T/29185-5 '-D__GLASGOW_HASKELL__=804' '-Ddarwin_BUILD_OS=1' '-Dx86_64_BUILD_ARCH=1' '-Ddarwin_HOST_OS=1' '-Dx86_64_HOST_ARCH=1' -
  I.stack-work/dist/x86_64-osx/Cabal-2.2.0.1/build/autogen -I. -I/Users/unhammer/.stack/programs/x86_64-osx/ghc-8.4.3/lib/ghc-8.4.3/base-4
  .11.1.0/include -I/Users/unhammer/.stack/programs/x86_64-osx/ghc-8.4.3/lib/ghc-8.4.3/integer-gmp-1.0.2.0/include -I/Users/unhammer/.stac
  k/programs/x86_64-osx/ghc-8.4.3/lib/ghc-8.4.3/include -ltdsodbc -L/Users/unhammer/src/tds/lib -L/Users/unhammer/.stack/programs/x86_64-o
  sx/ghc-8.4.3/lib/ghc-8.4.3/base-4.11.1.0 -L/Users/unhammer/.stack/programs/x86_64-osx/ghc-8.4.3/lib/ghc-8.4.3/integer-gmp-1.0.2.0 -L/Use
  rs/unhammer/.stack/programs/x86_64-osx/ghc-8.4.3/lib/ghc-8.4.3/ghc-prim-0.5.2.0 -L/Users/unhammer/.stack/programs/x86_64-osx/ghc-8.4.3/l
  ib/ghc-8.4.3/rts                                                                                                   
  /usr/bin/gcc returned ExitFailure 1 with error message:
  ld: can't link with bundle (MH_BUNDLE) only dylibs (MH_DYLIB) file
  '/Users/unhammer/src/tds/lib/libtdsodbc.so' for architecture x86_64                                                                     
  clang: error: linker command failed with exit code 1 (use -v to see                                                                     
  invocation)                                                                                                                             
  /usr/bin/gcc -fno-stack-protector /var/folders/bq/4xy9knvx413dwltf9c6ngvvm0000gt/T/29185-6.c -o /var/folders/bq/4xy9knvx413dwltf9c6ngvvm
  0000gt/T/29185-7 -ltdsodbc -L/Users/unhammer/src/tds/lib -L/Users/unhammer/.stack/programs/x86_64-osx/ghc-8.4.3/lib/ghc-8.4.3/base-4.11.1.0 -L/Users/unhammer/.stack/programs/x86_64-osx/ghc-8.4.3/lib/ghc-8.4.3/integer-gmp-1.0.2.0 -L/Users/unhammer/.stack/programs/x86_64-osx/ghc-8.4.3/lib/ghc-8.4.3/ghc-prim-0.5.2.0 -L/Users/unhammer/.stack/programs/x86_64-osx/ghc-8.4.3/lib/ghc-8.4.3/rts             
  /usr/bin/gcc returned ExitFailure 254 with error message:
  ld: can't link with bundle (MH_BUNDLE) only dylibs (MH_DYLIB) file
  '/Users/unhammer/src/tds/lib/libtdsodbc.so' for architecture x86_64
  clang: error: unable to execute command: Segmentation fault: 11
  clang: error: linker command failed due to signal (use -v to see invocation)
  /usr/bin/gcc -fno-stack-protector /var/folders/bq/4xy9knvx413dwltf9c6ngvvm0000gt/T/29185-8.c -o /var/folders/bq/4xy9knvx413dwltf9c6ngvvm
  0000gt/T/29185-9 -ltdsodbc -L/Users/unhammer/src/tds/lib -L/Users/unhammer/.stack/programs/x86_64-osx/ghc-8.4.3/lib/ghc-8.4.3/base-4.11.
  1.0 -L/Users/unhammer/.stack/programs/x86_64-osx/ghc-8.4.3/lib/ghc-8.4.3/integer-gmp-1.0.2.0 -L/Users/unhammer/.stack/programs/x86_64-os
  x/ghc-8.4.3/lib/ghc-8.4.3/ghc-prim-0.5.2.0 -L/Users/unhammer/.stack/programs/x86_64-osx/ghc-8.4.3/lib/ghc-8.4.3/rts
  /usr/bin/gcc returned ExitFailure 1 with error message:
  ld: can't link with bundle (MH_BUNDLE) only dylibs (MH_DYLIB) file
  '/Users/unhammer/src/tds/lib/libtdsodbc.so' for architecture x86_64
  clang: error: linker command failed with exit code 1 (use -v to see
  invocation)
  /usr/bin/gcc -fno-stack-protector /var/folders/bq/4xy9knvx413dwltf9c6ngvvm0000gt/T/29185-10.c -o /var/folders/bq/4xy9knvx413dwltf9c6ngvv
  m0000gt/T/29185-11 -c '-D__GLASGOW_HASKELL__=804' '-Ddarwin_BUILD_OS=1' '-Dx86_64_BUILD_ARCH=1' '-Ddarwin_HOST_OS=1' '-Dx86_64_HOST_ARCH
  =1' -I.stack-work/dist/x86_64-osx/Cabal-2.2.0.1/build/autogen -I. -I/Users/unhammer/.stack/programs/x86_64-osx/ghc-8.4.3/lib/ghc-8.4.3/b
  ase-4.11.1.0/include -I/Users/unhammer/.stack/programs/x86_64-osx/ghc-8.4.3/lib/ghc-8.4.3/integer-gmp-1.0.2.0/include -I/Users/unhammer/
  .stack/programs/x86_64-osx/ghc-8.4.3/lib/ghc-8.4.3/include                                                                              
  </code></pre>
  
  <p>Why can't <code>ld</code> link to MH_BUNDLE? Can cabal only link to <code>dylib</code>'s on mac, or do I need some special options?</p>
  
  <hr>
  
  <p>EDIT: Solved by instead linking to the dylib's that the .so links to.</p>