Jump to content

how to setting for my own header file and library


Recommended Posts

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.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...