47

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?

5
  • ar rcs lib/libevento.a event.o <- typo here or in the actual makefile? Commented Apr 15, 2013 at 21:28
  • 4
    It would appear as if you don't have the c libraries required for static linking. What platform are you compiling this on? Commented Apr 15, 2013 at 21:31
  • In this moment i'm compiling with CentOS. The same program was tested with Ubuntu and it worked. Commented Apr 15, 2013 at 21:32
  • 3
    Try installing the glibc static libraries - yum install glibc-static. If that doesn't work, your LIBRARY_PATH more than likely does not include the location of libc.a (although I would assume -L./lib would have that...) Commented Apr 15, 2013 at 21:34
  • Or try gcc main.c -L./lib -l event -o work -Wall Commented Apr 15, 2013 at 21:35

1 Answer 1

104

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Good to know! Have a gold badge.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.