Missing ___emutls_get_address with gcc-4.7 and openMP - gcc

I am trying to compile a program using a self-compiled GCC-4.7.1 on Mac OS 10.8.2. The program uses openMP and the compilation succeeds; however, when I try to run the program, the dynamic linker complains with
dyld: lazy symbol binding failed: Symbol not found: ___emutls_get_address
Referenced from: /usr/local/gcc-4.7.1/lib/libgomp.1.dylib
Expected in: /usr/lib/libSystem.B.dylib
dyld: Symbol not found: ___emutls_get_address
Referenced from: /usr/local/gcc-4.7.1/lib/libgomp.1.dylib
Expected in: /usr/lib/libSystem.B.dylib
This issue is constantly present in any program compiled with -fopenmp, including the MWE
#include <stdio.h>
int main() {
#pragma omp parallel
printf("Hallo!\n");
return 0;
}
Note that the solution suggested in What is the "___emutls_get_address" symbol?, namely adding -lgcc_eh in the linking phase, does not work (I still get the same dyld error message).

I had exactly the same problem too.
And I am new to openMP, and my skill is not that good to use the solution offered by Michal Fapso.
I solve this problem by using
brew link --overwrite gcc
and the problem is solved!
Maybe you can try to reinstall gcc to your Mac.

I had exactly the same problem. In my case it was caused by linking against a library (I don't remember which one) of an older version of gcc installed by XCode, which was in /usr/lib. When I corrected it to link against the newer gcc library of the version I used for compiling (in /usr/local) this error was fixed.
So just check your built executable and all the libraries it is linked with using
otool -L EXECUTABLE_OR_DYLIB
And if you find anything linked with a library of an older gcc, fix that.

Related

Rcpp compile issue in Rstudio

I face an error when compiling an simple rcpp code.
Rcpp::sourceCpp(code = '
#include <RcppArmadillo.h>
#ifdef _OPENMP
# include <omp.h>
#endif
// [[Rcpp::depends(RcppArmadillo)]]
// [[Rcpp::plugins(openmp)]]
// [[Rcpp::export]]
void omp_test()
{
#ifdef _OPENMP
Rprintf("OpenMP threads available: %d\\n", omp_get_max_threads());
#else
Rprintf("OpenMP not supported\\n");
#endif
}
')
When I compile the same code in R, not in Rstudio, it works well.
However, when I compile it in Rstudio, it shows an error like below:
[![enter image description here][1]][1]
> Rcpp::sourceCpp("R/utils/cpp_utils.cpp")
ld: warning: directory not found for option '-L/opt/R/arm64/lib'
ld: warning: dylib (/Library/Frameworks/R.framework/Resources/lib/libRlapack.dylib) was built for newer macOS version (20.0) than being linked (12.0)
ld: warning: dylib (/Library/Frameworks/R.framework/Resources/lib/libRblas.dylib) was built for newer macOS version (20.0) than being linked (12.0)
ld: warning: dylib (/opt/R/arm64/gfortran/lib/libgfortran.dylib) was built for newer macOS version (12.1) than being linked (12.0)
ld: warning: dylib (/Library/Frameworks/R.framework/R) was built for newer macOS version (20.0) than being linked (12.0)
Error in dyn.load("/private/var/folders/bm/_jr48kjs1ss7gk_vwbcxc7nr0000gn/T/RtmpFzxtqw/sourceCpp-aarch64-apple-darwin20-1.0.8/sourcecpp_6e64632dce2/sourceCpp_4.so") :
unable to load shared object '/private/var/folders/bm/_jr48kjs1ss7gk_vwbcxc7nr0000gn/T/RtmpFzxtqw/sourceCpp-aarch64-apple-darwin20-1.0.8/sourcecpp_6e64632dce2/sourceCpp_4.so':
dlopen(/private/var/folders/bm/_jr48kjs1ss7gk_vwbcxc7nr0000gn/T/RtmpFzxtqw/sourceCpp-aarch64-apple-darwin20-1.0.8/sourcecpp_6e64632dce2/sourceCpp_4.so, 0x0006): Library not loaded: #rpath/libgfortran.5.dylib
Referenced from: /private/var/folders/bm/_jr48kjs1ss7gk_vwbcxc7nr0000gn/T/RtmpFzxtqw/sourceCpp-aarch64-apple-darwin20-1.0.8/sourcecpp_6e64632dce2/sourceCpp_4.so
Reason: tried: '/usr/lib/libgfortran.5.dylib' (no such file)
To install rcpp, I followed the instructions in this page: Configuring compilers on Mac M1 (Big Sur, Monterey) for Rcpp and other tools
Moreover, as I want to debug the rcpp with lldb, I installed R from the website: https://mac.r-project.org/
I tried to link the libgfortran.5.dylib to usr/lib but permission was denied even with sudo.
I am using Mac monetery with M1,
Thanks for your solutions to the issue.
See this answer: Configuring compilers on Mac M1 (Big Sur, Monterey) for Rcpp and other tools
The issue is that your library path configured is invalid - it starts with "-L". This issue could be in a makefile for the project.
Check your RStudio build flags if you are specifying them in the command line. To specify the library path, you may need to use a lower-case L based on the documentation.
-l, --library=LIB library directory used for test installation
Alternatively, this site details the commands to check and set the library paths in RStudio.

dyld: Library not loaded: #rpath/libgfortran.3.dylib

I am trying to learn Fortran programming language, as a test I wrote a simple program like this:
!Fortran Program
program first
print *, "Hello World"
end program first
Then I threw this code file in to mac terminal and run gfortran first.f95 which then gave me an output of a.out as expected.
However, when I try to run the output in terminal by navigating into the output directory and typing ./a.out. It gave me this error output:
dyld: Library not loaded: #rpath/libgfortran.3.dylib
Referenced from: /Users/liang/Desktop/Programs/Fortran/Test/a.out
Reason: image not found
liang is my username.
I had the same problem, and my problem was caused because the library was not in default path and instead "anaconda" got in the path so that's why the compiler could not load it. I am a pure amateur user so I may explain not accurate in terms of technical words.
What I did was, I uninstalled my anaconda and deleted the folder in my Mac. Installed gcc "brew install gcc" again, and it worked! and then after, I installed my anaconda again, so now everything seemingly is ok.
My situation
I am also just learning, and I had a similar error message after compiling MUMPS library (http://mumps-solver.org).
I compiled the sequential version of MUMPS manually after brew installing the dependencies. When I ran the test examples, I got the same error message that libgfortran.3.dylib could not be loaded.
My brew gnu compiler is gcc version 9 and it is invoked by gcc-9, g++-9 and gfortran-9 (for C, C++ and Fortran respectively). Meanwhile gcc, g++ and gfortran invoke the compilers installed by anaconda.
How I solve it
I recompiled MUMPS using gcc-9 and gfortran-9 instead of gcc-9 and gfortran, and now everything works.

Linking gfortran libraries with fink

I installed the gcc 6.7 compiler with fink and I can now compile Fortran code, but not execute it. On runtime there is the following error:
dyld: Library not loaded: /sw/lib/gcc5/lib/libgfortran.3.dylib
and even after running 'fink selfupdate' this persists.
'which gfortran' returns '/sw/bin/gfortran'
and
'which gcc' returns '/usr/bin/gcc'
I suspect there is a problem with linking the libraries. How could I resolve this?
I resolved it eventually, thank you for your help. The problem was that gfortran was set to use version 5.5 by default. Higher versions were installed under gfortran-fsf-6 and gfortran-fsf-7 and their corresponding libraries were located in /sw/lib/gcc6 and /sw/lib/gcc7 (there was no /gcc5 present).
When I compile with
gfotran-fsf-6 "programname.f"
then everything is linked correctly.

dyld: Library not loaded, Reason: image not found

I used gdb normally until this week. Now running gdb I see:
(gdb) r
Starting program: /Volumes/MyProg
dyld: Library not loaded: #rpath/libCore.so
Referenced from: /Volumes/MyProg
Reason: image not found
(gdb)
How to fix it?
I have:
OSX 10.9
GNU gdb (GDB) 7.6 installed with MacPorts
P.S.
I have reinstalled gdb and Xcode. This does not help.
I see a lot of questions about dyld issues, but obviously I lack experience with libraries on OSX, and they appears to be useless for me.
For example this topic: dyld issues library not loaded
But how to download library again?
Or this topic: Dyld: Library not loaded
But how to find out install name? What is #rpath?
I solved this issue with "Embedded Binaries" in the General project settings.
i have solved this issue by changing the following settings
Go to Project Setting Your_Target->General->Embedded Binaries-> Click on + button and add your library here
How I fixed it:
libCore.so is a library from ROOT framework, which MyProg uses.
If I understand correctly, the message Library not loaded: #rpath/libCore.so Referenced from: /Volumes/MyProg Reason: image not found means that linker found the library, but can't use it.
Root, during installation uses clang by default. Meanwhile as I prefer gcc and MyProg uses gcc.
I have reinstalled root with gcc compiler:
./configure --with-cxx=g++ --with-cc=gcc --with-ld=g++
I have recompiled MyProg.
and now I can debug it with gdb.
You can find more information about rpath here: link
So you need to point the path to your libCore.so, but honestly I have not faced with this library so I don't know where is it located.
You can check also this answer to understand what it is rpath: answer
For Xcode 11 or above, there is another simpler solution which worked for me if you are using Cocoapods.
In your Podfile, add use_frameworks! after your Target line like this -
target 'YourAppName' do
use_frameworks!
Basically it adds all your pods as a framework in your framework folder.

Help on Compiling on AIX

Is there a site where I can find the symbols used in a particular library and its version.
For e.g. I m trying to compile some code on AIX using gcc, and it throws me a lot of undefined symbol errors
For example, here is an output:
ld: 0711-317 ERROR: Undefined symbol: .__fixdfdi
ld: 0711-317 ERROR: Undefined symbol: .__divdi3
ld: 0711-317 ERROR: Undefined symbol: .__moddi3
ld: 0711-317 ERROR: Undefined symbol: .__floatdidf
ld: 0711-317 ERROR: Undefined symbol: .__umoddi3
ld: 0711-317 ERROR: Undefined symbol: .__udivdi3
ld: 0711-317 ERROR: Undefined symbol: .__fixunsdfdi
Where do I go to find where these symbols are.
If I run the same gcc command on Linux, it runs fine.
I tried including -lgcc also but then again it throws undefined symbols for some register_frame ...blah blah...
and I m getting sick of AIX.
Any help on this would be appreciated..and please don't bother Googling on this issue.
You will end up no where.
Many have asked this kind of questions but no answers.
Thanks
It's been a long time since I compiled anything on AIX (thankfully) and I do feel your pain having spent a good year or so trying to get our company's JNI and other software libraries built on AIX.
I do seem to remember that GCC never worked particularly well as it always came up with similar errors. Is there any option to use the native compiler (xlC)?
Failing that I would check the ordering of your libraries, it plays a big part in making stuff work properly..
I take it that you have use the nm utility to iterate through every library in /usr/lib (etc) to find where the missing symbols are located?
Those are math symbols. Try adding -lm to your link line.
This is because you used the gcc to compile a library you want to link to a code compiled with xlc. Or at least is my case
You have 2 options:
use the xlc instead of gcc for all the compilation (don't mix gcc and xlc)
compile with xlc but calling also the gcc libraries, for instance:
sudo find / -name libgcc.a
/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.2.0/libgcc.a
/opt/IBM/xlC/13.1.0/bin/xlC -g -o MyBIN MyBIN.o -L/usr/etctera -
L/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.2.0/ -lgcc -letcetera
Mostly questions:
Which version of GCC?
Which version of AIX are you on?
Which version of AIX was your copy of GCC built for?
What exactly is the link line you are using?
I've seen that sort of error when using a version of GCC compiled on a down-version of AIX. For example, if the GCC was compiled for AIX 4.3.3 and is being run on AIX 5.x. Usually, if GCC was compiled on an up-version of AIX, it won't run on the down-version, so that is unlikely to be the problem.
One other (rather unlikely) possibility: is your GCC installed where it was compiled to expect to be installed? When you build it, you specify (possibly implicitly) the install location (by default, under /usr/local). If you have your copy installed somewhere else, but there's an old GCC in /usr/local and your copy expects to be installed in /usr/local, then you can run into this sort of problem. This is much less likely than version mismatching.
Listed external symbols are from libgcc so add of -lgcc is correct. And register_frame also is part of libgcc but only for 32-bit. Check if you use the same bit depth mode for you compiler, linker and libraries.

Resources