Linux: /usr/bin/ld: cannot find -lc Error and Solution

The error message “/usr/bin/ld: cannot find -lc” usually occurs when the linker is unable to find the standard C library libc.so while compiling a program. This can happen if the library is not installed on your system or if the linker is not able to find it in the default library search path.

To resolve this issue, you can try the following steps:

  1. Check if the library is installed: You can check if the standard C library is installed on your system by running the following command:
locate libc.so

If the library is installed, you should see the location of the library file in the output.

  1. Add the library location to the linker search path: If the library is installed but the linker is unable to find it, you can add the library location to the linker search path. You can do this by adding the following option to the LD_LIBRARY_PATH environment variable:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/libc.so

Replace /path/to/libc.so with the actual location of the library file on your system.

  1. Reinstall the library: If the library is not installed on your system, you can install it using your system’s package manager. For example, on a Debian-based system, you can use the following command:
sudo apt-get install libc6

On a Red Hat-based system, you can use the following command:

sudo yum install glibc

After installing the library, try compiling your program again and the error should be resolved.

Note: These steps are a general guide and may vary depending on your specific system and the specific library involved. If you encounter any issues or if the error persists, you may need to consult the documentation for your system or the website of the library for further assistance.

Leave a Comment