Jump to content
Sign in to follow this  
Xcross87

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.

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...