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

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

The error message /usr/bin/ld: cannot find -lc indicates that the linker is unable to find the C library (libc). This error can occur when you are trying to compile a program on a Linux system and the necessary libraries are not installed or not in the linker's search path.

To resolve this error, you can try the following solutions:

  1. Install the missing libraries. On most Linux systems, the C library is part of the glibc package. To install glibc, use your package manager. For example, on a Debian-based system, you can use the following command:
refer t‮uttual:o‬ri.com
sudo apt-get install libc6-dev

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

sudo yum install glibc-devel
  1. Add the library directory to the linker's search path. The linker looks for libraries in specific directories by default. If the necessary libraries are not in one of these directories, you can add the directory to the linker's search path using the -L option. For example:
gcc -L/path/to/library -o myprogram myprogram.c

This will tell the linker to search for libraries in the /path/to/library directory.

  1. Link to the library using the full path. Instead of using the -L option, you can specify the full path to the library when linking. For example:
gcc -o myprogram myprogram.c /path/to/library/libc.a

This will tell the linker to link to the libc library located in the /path/to/library directory.

I hope these solutions help resolve the error and allow you to successfully compile your program. Let me know if you have any questions.

Created Time:2017-10-16 14:38:53  Author:lautturi