Search code examples
gccgfortrandylibdyld

Do multiple gcc versions confuse dylibs (libgcc_s.1.dylib) and prevent binaries from running?


I've encountered an error while trying to run Bayescan 2.0.

This is on Mac OS X 10.9.2 Mavericks. When simply calling the program with no input file, the help menu displays normally.

BayeScan2.1_macos64bits --help

However when executing the program with input file as argument...

BayeScan2.1_macos64bits test.input

this error displays:

dyld: lazy symbol binding failed: Symbol not found: ___emutls_get_address
  Referenced from: /usr/local/lib/libgomp.1.dylib
  Expected in: /usr/local/lib/libgcc_s.1.dylib

dyld: Symbol not found: ___emutls_get_address
  Referenced from: /usr/local/lib/libgomp.1.dylib
  Expected in: /usr/local/lib/libgcc_s.1.dylib

Trace/BPT trap: 5

The program has executed perfectly fine in the past. My hunch is that the wrong gcc libs are referenced in 'libgcc_s.1.dylib' but I have no clue how to fix. I've tried installing various versions of gcc and gfortran, but having multiple installs seems generally like a bad idea. Both Macports and Homebrew are installed.

There has been another possibly related install issue with an R-forge package with a 'symbol not found' error message that also references libgcc_s.1.dylib. Unfortunately I have no clue what this dylib is, how to search for symbols, link correct versions of gcc, etc.

My active gcc version seems to be LLVM 5.1:

gcc --version

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.1.0
Thread model: posix

And gfortran version is 4.9:

gfortran --version

GNU Fortran (GCC) 4.9.0

However it looks like multiple gcc libs might exist?

ls -1 /usr/local/lib/gcc

i686-apple-darwin8/
i686-apple-darwin8.8.1/
powerpc-apple-darwin8/
x86_64-apple-darwin13.0.0/

Also, it looks like other gcc/gfortran versions in /opt/local/bin:

ls -1 /opt/local/bin/*gfortran*; ls -1 /opt/local/bin/*gcc*

/opt/local/bin/gfortran-mp-4.7*
/opt/local/bin/gfortran-mp-4.8*
/opt/local/bin/x86_64-apple-darwin13-gfortran-mp-4.7*
/opt/local/bin/x86_64-apple-darwin13-gfortran-mp-4.8*
/opt/local/bin/gcc-ar-mp-4.7*
/opt/local/bin/gcc-ar-mp-4.8*
/opt/local/bin/gcc-mp-4.7*
/opt/local/bin/gcc-mp-4.8*
/opt/local/bin/gcc-nm-mp-4.7*
/opt/local/bin/gcc-nm-mp-4.8*
/opt/local/bin/gcc-ranlib-mp-4.7*
/opt/local/bin/gcc-ranlib-mp-4.8*
/opt/local/bin/x86_64-apple-darwin13-gcc-4.7.3*
/opt/local/bin/x86_64-apple-darwin13-gcc-4.8.3*
/opt/local/bin/x86_64-apple-darwin13-gcc-ar-mp-4.7*
/opt/local/bin/x86_64-apple-darwin13-gcc-ar-mp-4.8*
/opt/local/bin/x86_64-apple-darwin13-gcc-mp-4.7*
/opt/local/bin/x86_64-apple-darwin13-gcc-mp-4.8*
/opt/local/bin/x86_64-apple-darwin13-gcc-nm-mp-4.7*
/opt/local/bin/x86_64-apple-darwin13-gcc-nm-mp-4.8*
/opt/local/bin/x86_64-apple-darwin13-gcc-ranlib-mp-4.7*
/opt/local/bin/x86_64-apple-darwin13-gcc-ranlib-mp-4.8*

Are the multiple versions of gcc/gfortran causing this error? Any other ideas? Any help is welcome! Sorry I can't be any more descriptive of my fortran setup.

EDIT: Here is a related post: https://github.com/mash/node-imagemagick-native/issues/17

EDIT #2: This error is elicited by multiple programs. To illustrate, here is the error message while trying to run the program Genepop:

Genepop

Genepop version 4.2.1

Unable to open file genepop.txt
Unable to open file dyld: lazy symbol binding failed: Symbol not found: ___emutls_get_address
  Referenced from: /usr/local/lib/libstdc++.6.dylib
  Expected in: /usr/local/lib/libgcc_s.1.dylib

dyld: Symbol not found: ___emutls_get_address
  Referenced from: /usr/local/lib/libstdc++.6.dylib
  Expected in: /usr/local/lib/libgcc_s.1.dylib

Trace/BPT trap: 5

If I temporarily mask libgcc_s.1.dylib...

sudo mv /usr/local/lib/libgcc_s.1.dylib /usr/local/lib/libgcc_s.1.dylibTEMP 
Genepop

Genepop version 4.2.1

Unable to open file genepop.txt
Unable to open file dyld: lazy symbol binding failed: Symbol not found: ___emutls_get_address
  Referenced from: /usr/local/lib/libstdc++.6.dylib
  Expected in: /usr/lib/libSystem.B.dylib

dyld: Symbol not found: ___emutls_get_address
  Referenced from: /usr/local/lib/libstdc++.6.dylib
  Expected in: /usr/lib/libSystem.B.dylib

Trace/BPT trap: 5

And finally if I mask the entire /usr/local directory, this solves the problem for some programs (Genepop)! But not for others (Bayescan):

sudo mv /usr/local /usr/localTEMP

BayeScan2.1_macos64bits test.input

dyld: Library not loaded: /usr/local/lib/libgomp.1.dylib
  Referenced from: /Users/maierpa/programs/Bayescan
  Reason: image not found
Trace/BPT trap: 5

Solution

  • Looks like your build of BayeScan2.1_macos64bits was linked against a newer libgcc than the copy you have at /usr/local/lib/libgcc_s.1.dylib

    How was /usr/local/lib/libgomp.1.dylib installed on your system? (Perhaps it came along for the ride with an installation of GCC from homebrew/MacPorts/something else?)

    I noticed that after installing GCC 4.8 via homebrew, I have a copy of libgomp.1.dylib here:

    /usr/local/Cellar/gcc/4.8.3_1/lib/gcc/x86_64-apple-darwin13.2.0/4.8.3/libgomp.1.dylib

    And the prebuilt BayeScan2.1_macos64bits binary runs on my system if I tell it to search that dir:

    DYLD_LIBRARY_PATH=/usr/local/Cellar/gcc/4.8.3_1/lib/gcc/x86_64-apple-darwin13.2.0/4.8.3/ ./BayeScan2.1_macos64bits

    For a smoother experience on OS X 10.9 and above, you might consider rebuilding BayeScan/genepop with the clang compiler instead of GCC. Building with clang would circumvent the problem of the prebuilt BayeScan's dependency on a new-and-improved libstdc++, which seems to be causing issues here (now that the aging libstdc++ shipped with OS X 10.9+ appears to be missing crucial symbols).

    Unfortunately it looks like the stock version of clang provided with the Xcode command line tools doesn't support -fopenmp as of this writing, which you need to build the BayeScan dependency libgomp.

    So building libgomp probably requires installing clang-omp for now and using it instead of Apple's stock clang: http://clang-omp.github.io/