I have 3 files: main.c, mylib.h, mylib.c
Now I want to put mylib.h into : /usr/include/mydir/mylib.h
And I create a static library: libmylib.a, and put into the folder: /usr/lib/mydir/libmylib.a
Then I compile: $ gcc -o main main.c
Then I got linking error
Code:
main.c:(.text+0x3e): undefined reference to `extract_v1'
main.c:(.text+0x7b): undefined reference to `modify_v1'
collect2: ld returned 1 exit status
So I try with -l options: $ gcc -o main main.c -lmylib
I still got error
Code:
/usr/bin/ld: cannot find -lmylib
collect2: ld returned 1 exit status
Any idea about this?
Also, I want to ask about
: how to create my own header and library to put into /usr/include/mylib/ and /usr/lib/mylib/, so when I use function in my program, the compiler will automatically link to library.
It's like when you #include <stdio.h>, and you compile: $ gcc -o program program.c, you don't need to specify any linking folder or library.