[SOLVED c++] making a library ?

Started by
3 comments, last by DpakoH 15 years, 8 months ago
hi all, i am writing a simple graphical application (based on gtk+) and i have couple of classes handling data management and drawing data (e.g. points in XY coord system).i want to create a simple library from these classes so it can be used not only for this certain project. i am wondering how can i do that ? it is supposed to be a linux library, (on windows i could manage to do smth with vs2008 but i am not very profound of linux) and any help will be greatly appreciated. best, y. [Edited by - DpakoH on July 31, 2008 4:37:08 AM]
Advertisement
it is something like gcc -o [names of files]. Type:

man gcc

on the command line.
Here is what you do for a static library:

  1. Compile all of your code to object files:
    gcc -c file1.c
    gcc -c file2.c
    ...

  2. Create an archive containing all of the object code:
    ar rcs libraryname.a file1.o file2.o ...

  3. Create an index for the library:
    ranlib libraryname.a

  4. Link new code to your library:
    gcc libraryname.a code_that_uses_lib.c



That should at least get you started.
You shouldn't need to use ranlib if you used rcs or -rcs.

IIRC the 's' parameter already builds the index.
That is unless you're using an old version of ar.



thx for the answers,
i've been away for some time and i just checked this tread again.
again thx for the help , and i see the this is the way to create a static library (or maybe i am wrong again). i will try that but i think it will work.


best,
y.

This topic is closed to new replies.

Advertisement