• Advertisement
Sign in to follow this  

[SOLVED c++] making a library ?

This topic is 3549 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.



Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement