Error: ld: cannot find -lm

Published:07/26/2012   Last Updated:07/26/2012


Problem : compiling with -fast or -static causes a linker error "ld: cannot find -lm"

Environment : Redhat Enterprise Linux 6, Fedora Core 11, 12, 13, 14 other linux distros possible

Root Cause :  RHEL 6, FC12, 13, 14 do not ship with static versions of glibc OR the libraries are in a directory that is not normally pathed.  Thus, there is no static version of libm to link by default.  (the linux community is trying to discourage static linking and move the community to a dynamic linking model.  Thus, recent linux distros are not shipping/installing glibc-static by default OR are putting the static libs in paths that are not searched by default.)

Resolution :

If you want to link statically, that is with -static or -fast (which contains -static), you will need the static versions of glibc.  Keep in mind that static linking is being discouraged by the larger linux community.  You may, of course, use -static-intel to statically link the Intel libraries.  However, if you want to also statically link the system libraries in glibc you will need the static versions of glibc.

CASE 1, PATHS: 64bit compiler and x86_64 64bit OS:   RHEL 6.x distros may put the libs in path not normally searched, /usr/lib/x86_64-redhat-linux5E/lib64/   Add this path explicitly:

Possible workarounds are:
1) Specify library location using -L option
ifort -static hello.f90 -L/usr/lib/x86_64-redhat-linux5E/lib64/
2) Add the location of libraries to LIBRARY_PATH variable

SECOND CASE: 32 bit OS/gcc/Intel Compiler and/or static libs are not found in /usr/lib/x86_64-redhat-linux5E

Install the static version of glibc.  Research your distribution for the appropriate package to install.  For example, for RHEL 6 and FC12 and FC13:

yum install glibc-static

yum install glibc-static.x86_64

yum install glibc-static.i686

(you may have to research and find a 32bit version of glibc-static.  Use rpmfind or some other web search to find an appropriate 32bit version of glibc-static that matches the 64bit version you installed above with yum).

Another work-around: avoid static linking - don't use the -static or -fast compiler options.



Product and Performance Information


Intel's compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice.

Notice revision #20110804