Archived

This topic is now archived and is closed to further replies.

avianRR

Creating Library files?

Recommended Posts

How do you create library files? I''m working on several projects. They all use the same basic group of source files and I''d like to put them in a library file so that I only have to include one file for all of them.

Share this post


Link to post
Share on other sites
Well,

It depends if you want to make shared libraries or static libraries.

The general procedure to do, say for C and assuming GNU tools, for a shared library is:

user@machine:~ $ gcc -c -fpic module1.c module2.c module3.c
user@machine:~ $ ld -Bshareable -o mylib.so.1.0 module1.o module2.o module3.o


Then obviously you''ll have to link against this library to use it when you compile programs that use those library calls.


FYI HTH,

.zfod

Share this post


Link to post
Share on other sites
Also,

Remember to do the ldconfig stuff if you''re using such a system to create the necessary links and cache. Also, if you''re using a non-standard trusted lib directory you can add it. If not, be sure to set your LD_LIBRARY_PATH accordingly.


.zfod

Share this post


Link to post
Share on other sites
quote:
Original post by zfod
It depends if you want to make shared libraries or static libraries.



Static. I wan''t the stuff compiled directly into my programs.

Thanks for the info on the shared lib''s though I might be makeing one of those eventually too.

Share this post


Link to post
Share on other sites
Ahh,

Ok, just do the following with your object code:

user@machine:~ $ ar rc mylib.a module1.o module2.o module3.o
user@machine:~ $ ranlib mylib.a

This creates the static library mylib.a that you can link against.


HTH,

.zfod

Share this post


Link to post
Share on other sites
quote:
Original post by zfod
user@machine:~ $ ar rc mylib.a module1.o module2.o module3.o
user@machine:~ $ ranlib mylib.a



Tried that. It dosn''t want to work right. I have to have a global instance of each class object in the library or the I get undefined referance errors on all the class function calls in my project.

Share this post


Link to post
Share on other sites