简体   繁体   English

/ usr / bin / ld:使用makefile编译时找不到-lc

[英]/usr/bin/ld: cannot find -lc while compiling with makefile

Context first: I have a header (event.h), a program called event.c, and the main program main.c. Context first:我有一个头文件(event.h),一个名为event.c的程序,以及主程序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.o),然后在一个单独的文件夹中生成一个静态库(libevent.a),然后生成可执行程序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? 有没有办法在不安装任何东西的情况下编译它?

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. 链接器找不到静态链接库所需的C库。 You can try and see if libc.a already exists on your system by calling locate libc.a . 你可以试试,看看是否libc.a已经通过调用您的系统上存在locate libc.a If this returns, add an appropriate library flag pointing to the directory that includes libc.a . 如果返回,请添加指向包含libc.a的目录的相应库标志。

If libc.a is not installed, you unfortunately need to install the library if you want to compile your library statically. 如果未安装libc.a则遗憾的是,如果要静态编译库,则需要安装库。 Since you stated you are on CentOS, you should be able to accomplish this with yum install glibc-static . 既然你说你在CentOS上,你应该可以用yum install glibc-static来完成这个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM