본문 바로가기
Working on

/usr/bin/ld: cannot find -lm or cannot find -lc

by Warehaus 2021. 11. 29.

Recently, I'm working on package builds to operate our own software.

 

However, an error message made me stuck in but I recently resolved it so, leave this working log for me and others.

 

Issues

 

For some reasons, we needed to build with -O2 -static options for g++.

As the changes,  I got the error messages like:

 

 

/user/bin/ld: cannot find -lm

/usr/bin/ld: cannot find -lc

collect2: error: ld returned 1 exit status

....

 

Since the only change was the g++ option '-static' , thankfully my colleague suggested me to install glibc-static

 

Got another issue

 

So,  I installed glib-static-2.17-317* which is latest one I found and installed it.

But, I got dependency error like:

 

glibc-devel = 2.17.317.... needed by glibc-static-2.17.317....

 

but I thought my machine has glibc-devel as this output from rpm -q glibc-devel:

 

$ glibc -q glibc-devel

$ glibc-devel-2.17.157.el7..

 

At that time, I was not aware of the package version so, just installed what I had like:

 

$ rpm --nodeps glibc-static-2.17....

 

It was successfully installed and g++ command for build didn't show the error 'cannot find -lm/ -lc'.

 

But, the result of build didn't work well.

 

Resolve the problem

 

I've tried some resolutions like ... remove files and clone the repository again.. reinstall the rpm package .. but that was not the solution.

 

While I was trying several dumb works, finally, I found the version of glib-static was not maching to glibc-* rpm packages :

 

$ rpm -q glibc

glibc-2.17-157 ....

$ rpm -q glibc-devel

glibc-devel-2.17-157...

$ rpm -q glibc-static

glibc-static-2.17-317...

 

To match the version of glibc things, I removed glib-static-2.17-317 .. and downloaded glib-static-2.17.157* to re-install it.

 

After re-installation, I don't see any error messages above and the built tools work well.