Let me explain the context first. I have a header with a function declaration, a .c program with the body of the function, and the main program.
foo.h
#ifndef _FOO_H_ #define _FOO_H_ void foo(); #endif foo.c
#include<stdio.h> #include "include/foo.h" void foo() { printf("Hello\n"); } mainer.c
#include <stdio.h> #include "include/foo.h" int main() { foo(); return 0; } For the purpose of this program, both the header and the static library need to be in separate folders, so the header is on /include/foo.h and the static library generated will be on /lib/libfoo.a, and both .c programs on the main directory. The idea is to generate the object program, then the static library, then linking the static library to create the executable, and finally executing the program.
I have no problem in both creating the object program and the static library.
$ gcc -c foo.c -o foo.o $ ar rcs lib/libfoo.a foo.o But when I try to link the static library...
$ gcc -static mainer.c -L. -lfoo -o mainfoo It gaves to me an error, claiming the static library can't be found
/usr/bin/ld: cannot find -lfoo collect2: ld returned 1 exit status It's strange, considering I asked before how to work with static libraries and headers on separate folders and in this case the static libraries were found. Any idea what I'm doing wrong?
libnot.