Library in library...

S

Sweep

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.
 
J

Jack Klein

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top