Xcross87 Posted May 8, 2010 Report Share Posted May 8, 2010 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 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 /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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.