/ usr / bin / ld:使用makefile编译时找不到-lc [英] /usr/bin/ld: cannot find -lc while compiling with makefile

查看:646
本文介绍了/ usr / bin / ld:使用makefile编译时找不到-lc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上下文首先:我有一个头文件(event.h),一个名为event.c的程序和主程序main.c.这个程序将被编译,首先生成一个对象程序(event.o),然后在一个单独的文件夹中创建一个静态库(libevent.a),然后生成可执行程序work1.exe
$ b $为了做到这一点,我创建了这个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
  
$ b code $ 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:找不到-lc
collect2:ld返回1退出状态$ b $ make:*** [work1]错误1

任何想法发生了什么?有没有办法编译这个没有安装任何东西?

解决方案

具体错误是以下行:

  / usr / bin / ld:找不到-lc 

链接程序无法找到静态链接库所需的C库。您可以通过调用 locate libc.a 来查看系统中是否已经存在 libc.a 。如果返回,则添加一个指向包含 libc.a 的目录的适当库标志。



如果<$没有安装c $ c> libc.a ,如果你想静态编译你的库,不幸的是你需要安装库。既然你说过你在CentOS上,你应该可以用 yum install glibc-static 来完成。


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

To do this I created this 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:

 $ 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. 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.

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.

这篇关于/ usr / bin / ld:使用makefile编译时找不到-lc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆