Skip to main content
gamedev.net
🔒 Locked

Creating Library files?

Started by avianRR May 28, 2003 at 6:21 PM 4 replies 1.1k views
Original Post
avianRR
avianRR
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]
zfod
zfod
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
zfod
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
avianRR
avianRR
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]
zfod
zfod
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
avianRR
avianRR
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]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.