分享

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

 吾乃阿尔法 2013-11-17

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.



    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多