在使用makefile编译时,无法找到-lc

时间:2022-04-02 02:14:20

Context first: I have a header (event.h), a program called event.c, and the main program main.c. This program will be compiled, generating first a object program (event.o), then a static library (libevent.a) in a separate folder, and then the executable program work1.exe

上下文第一:我有一个标题(event.h),一个叫做event的程序。c,主程序主程序主程序。这个程序将被编译,首先生成一个对象程序(event.o),然后在一个单独的文件夹中生成一个静态库(libeventa),然后生成可执行程序work1.exe

To do this I created this makefile:

为此,我创建了这个makefile:

work1 : main.c libevent.a
    gcc -static main.c -L./lib -levent -o work1 -Wall

event.o: event.c
gcc -c event.c -Wall

libevent.a: event.o
ar rcs lib/libevento.a event.o 

clean: 
rm work1 *.o

The result of executing the makefile leads to this error:

执行makefile的结果导致以下错误:

 $ make
 gcc -c event.c -Wall
 ar rcs lib/libevent.a event.o 
 gcc -static main.c -L./lib -levent -o work1 -Wall
 /usr/bin/ld: cannot find -lc
 collect2: ld returned 1 exit status
 make: *** [work1] Error 1

Any idea what is going on here? Is there a way to compiling this without installing anything?

你知道这是怎么回事吗?有没有一种不用安装任何东西就可以编译的方法?

1 个解决方案

#1


44  

The specific error is the following line:

具体误差为:

/usr/bin/ld: cannot find -lc

The linker cannot find the C libraries required for statically linking your library. You can try and see if libc.a already exists on your system by calling locate libc.a. If this returns, add an appropriate library flag pointing to the directory that includes libc.a.

链接器无法找到静态链接库所需的C库。你可以试着看看libc。通过调用locate libc.a,系统上已经存在a。如果返回,则添加一个适当的库标志指向包含libc.a的目录。

If libc.a is not installed, you unfortunately need to install the library if you want to compile your library statically. Since you stated you are on CentOS, you should be able to accomplish this with yum install glibc-static.

如果libc)。a没有安装,不幸的是,如果您想静态地编译库,您需要安装库。既然您已经声明您正在使用CentOS,那么您应该能够使用yum安装glibc-static来实现这一点。

#1


44  

The specific error is the following line:

具体误差为:

/usr/bin/ld: cannot find -lc

The linker cannot find the C libraries required for statically linking your library. You can try and see if libc.a already exists on your system by calling locate libc.a. If this returns, add an appropriate library flag pointing to the directory that includes libc.a.

链接器无法找到静态链接库所需的C库。你可以试着看看libc。通过调用locate libc.a,系统上已经存在a。如果返回,则添加一个适当的库标志指向包含libc.a的目录。

If libc.a is not installed, you unfortunately need to install the library if you want to compile your library statically. Since you stated you are on CentOS, you should be able to accomplish this with yum install glibc-static.

如果libc)。a没有安装,不幸的是,如果您想静态地编译库,您需要安装库。既然您已经声明您正在使用CentOS,那么您应该能够使用yum安装glibc-static来实现这一点。