Library in library...

Discussion in 'C++' started by Sweep, Dec 8, 2003.

  1. Sweep

    Sweep Guest

    A question about linking with a static library that uses code from another
    static library.

    Suppose we have files A.h and A.cpp defining class A:

    //////////////////////
    // A.h
    class A {
    public:
    A();
    int get_value();
    };
    //////////////////////

    //////////////////////
    // A.cpp
    #include "A.h"
    A::A() {}
    int A::get_value() {
    return 1;
    }
    //////////////////////

    We compile A.cpp and create a library A.lib.

    Now suppose we have another set of files B.h and B.cpp defining class B:

    //////////////////////
    // B.h
    #include "A.h"
    class B {
    public:
    B();
    int get_value();
    private:
    A a();
    };
    //////////////////////

    //////////////////////
    // B.cpp
    #include "B.h"
    B::B() {}
    int B::get_value() {
    return (2*a.get_value());
    }
    //////////////////////

    Now suppose that we have a file test.cpp using class B:

    //////////////////////
    // test.cpp
    #include <iostream.h>
    #include "B.h"
    B b();
    cout << b.get_value();
    //////////////////////

    In order for this file to be built the following must be true (correct me if
    I am wrong):
    1. the compiler must be aware of the paths to both A.h and B.h
    2. both A.lib and B.lib must be given to the linker

    So, in order for one to use B.lib, one should also have, or be willing to
    provide paths and other arguments about, A.lib!

    So the question is:

    Is there a way to create B.lib and an accompanying header file (say B2.h) in
    such a way so that I only need to include this B2.h and link to B.lib in
    order to compile a module that uses class B and create an executable? In
    other words, is it possible to build B2.h and B.lib in such a way that it
    B.lib is redistributable without needing to be accompanied by A.h and A.lib?

    Thanx to all in advance

    Sweep

    P.S. Forgive me for any wrong terminology/expressions, English is not my
    native language.
     
    Sweep, Dec 8, 2003
    #1
    1. Advertising

  2. Sweep

    Jack Klein Guest

    On Mon, 8 Dec 2003 21:03:17 +0200, "Sweep" <> wrote in
    comp.lang.c++:

    > A question about linking with a static library that uses code from another
    > static library.


    The C++ language does not define static libraries or how linking is
    performed at all. You need to ask this in a support group for your
    particular compiler/linker combination. It is a compiler-specific
    issue, not a language one.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c /faq
     
    Jack Klein, Dec 9, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mythran
    Replies:
    0
    Views:
    2,494
    Mythran
    Aug 24, 2004
  2. Alan Ferrandiz [MCT]
    Replies:
    0
    Views:
    470
    Alan Ferrandiz [MCT]
    Sep 11, 2004
  3. Replies:
    6
    Views:
    886
    red floyd
    May 10, 2005
  4. iceColdFire

    Static library Vs. Dynamic library

    iceColdFire, May 17, 2005, in forum: C++
    Replies:
    3
    Views:
    17,128
  5. Replies:
    0
    Views:
    3,451
Loading...

Share This Page