views:

33

answers:

2

Hi,

I'm trying to create a static library using Visual Studio 2005, consisting of multiple header and source files, for example:

A->B, A->C, A->D B->E

(A->B = B is #include-d in A)

I managed to compile a static library by following the MSDN tutorial and put all the files in a project file in Visual Studio, and compiled a .lib. The problem is, I only want others to have access to one header file (A), and not the others, but because A includes the other files, after I have compiled the library and tried to use this in another project, when I only include the static library and header file from A, it says it can't find the header files for B, C, D and E. Is there a way to solve this issue?

One method (not the most elegant and simple method) I thought of is to put all the codes into one set of header/source files, but that's a lot of work and can get quite tricky...

A: 

Not without refactoring.

When creating libraries I like to arrange my header libraries into public and private headers. You can have a private header include a public header but not vice versa.

You're going to need to clean up your header files to cleanly separate the public and private parts of your API.

Unfortunately, without knowing why your header files are structured the way they are, I can't offer more specific advice.

R Samuel Klatchko
The codes were designed to be very modular (by the guy that worked on it before me), which meant that functions that do different things are in their own files. For example, my main files are "math.h/math.cpp", then I might have four other sets called "add", "subtract", "multiply" and "divide". My main header file would be something like:#include "add"#include "subtract"...namespace math{class mymath{...Maybe not the best example, but I hope you see what I mean.Looks like I'll have a bit of refractoring to do then :(
chocobo_ff
Hi again, could you please give me an example or a link for private and public headers? I had a quick read and get the general concept from here: http://os.inf.tu-dresden.de/~hohmuth/prj/preprocess/ , but it includes the private header in the public header and that's what's confusing me... many thanks! :)
chocobo_ff
A: 

When designing a library, it's important to separate the interface you want to expose from the implementation of your library.

Just create a header file with the stuff you want to expose to users of your library, or e.g. just don't have A include the other header files.

nos