Creating Library files?

Started by
4 comments, last by avianRR 20 years, 10 months ago
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.
------------------------------Piggies, I need more piggies![pig][pig][pig][pig][pig][pig]------------------------------Do not invoke the wrath of the Irken elite. [flaming]
Advertisement
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
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
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.
------------------------------Piggies, I need more piggies![pig][pig][pig][pig][pig][pig]------------------------------Do not invoke the wrath of the Irken elite. [flaming]
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
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.
------------------------------Piggies, I need more piggies![pig][pig][pig][pig][pig][pig]------------------------------Do not invoke the wrath of the Irken elite. [flaming]

This topic is closed to new replies.

Advertisement