Search code examples
c++compiler-constructioneclipse-cdt

Building a new library on top of another library (SDL and Eclipse)


I am working on a project with SDL. I feel like a lot of my code could/should be reusable for any other projects I might want to take on.

I was going to start a library project, but I don't know how to go about linking to the SDL libraries.

Usually, I go to Project Settings and edited Mingw32 Linker to include the libraries (ming32, SDLmain, and SDL). But the linker does not show up in the settings.

So my questions:

Is there no linker settings because building a library is only a compiling operation?

And in general, is it possible to build a library on top of the existing libraries? That is, write my library using SDL functions and stucts. Or would I have to get the source code and rebuild entirely with my code included?

Also, advice on shared vs. static in this instance?

(Also, any advice for where to go about learning more about compilers and linkers and such. I got through data structures in school but no farther)


Solution

  • As an introduction, you have to distinguish very well static library from dynamic ones, they are completely different beasts... said that, to your questions:

    Is there no linker settings because building a library is only a compiling operation?

    I guess you are creating a static library in this case. A static library is simply the collection in one single object file of all the individual object files (i.e., the .o files produced by the compiler) that make up your source tree. No more, no less.

    With a static library you don't need to specify which are the dependencies, since it is understood that it is when compiling the final executable that your library will be linked with all the other libraries that it depends upon. Therefore it is only at that time (final executable build) that any missing symbol will be detected, and all other libraries must be available.

    A shared library (also dynamic library), is an executable file that embeds all the static libraries that it depends upon. It can also have external dependencies with other shared library, which would not be embedded.

    And in general, is it possible to build a library on top of the existing libraries? That is, write my library using SDL functions and stucts. Or would I have to get the source code and rebuild entirely with my code included?

    It is perfectly possible, both for static and dynamic libraries.

    Also, advice on shared vs. static in this instance?

    In this instance it is not possible to advice, because you don't specify enough information. Look at this: When to use dynamic vs. static libraries, and this, to have a sort of guideline.

    (Also, any advice for where to go about learning more about compilers and linkers and such. I got through data structures in school but no farther)

    I think that the two links above give you plenty of information. If you want to further go into details, you could start from this wikipedia article and browse from there.