views:

30

answers:

1

Hi,

I don't code with lib linking and dll for most of the time, recently when I do, i realized there could be something very wrong with the way i do my #include.

Is the following the correct/desirable way to do #include?

suppose i have 3 projects (1) dll_A (2) dll_B (3) exe_1. dll_A depends on dll_B, exe_1 depends one dll_A.

the way i do my #include is as follows:

dll_B.h ----> no dependency
dll_B.cpp -----> #include dll_B.h
dll_A.h -------> #include dll_B.h
dll_A.cpp -------> #include dll_A.h
exe_1.h --------> #include dll_A.h

From here it can be seen that exe_1.h indirectly includes dll_b.h which is kind of bad for me, because I want exe_1.h to be independent of dll_b.h... yet, I am not sure if that is possible because how else can exe_1 link to dll_b?

EDIT: Example dependency

// dll_B.h
struct dataB{};

// dll_A.h
#include dll_B.h
dataB* A_function_ptr(); // (any difference for implementing PIMPL?)
dataB& A_function_ref();
dataB A_function_copy();

// exe_1.cpp
#include dll_A.h
// ... it seems naturally #include-sion of dll_B.h is necessary? Can it be avoided?
+1  A: 

If dll_B is just an implementation detail of dll-A, then don't include [dll_B.h] from [dll_A.h], just include it from [dll_A.cpp].

Avoiding that header dependency may require a little redesign.

E.g. you may want to think about PIMPL idiom for [dll_A].

More details are impossible to state without knowing more details... :-)

Cheers & hth.,

PS: Linking has nothing to do with header files, except that with some Windows compilers (notably MSVC) a header file can include a #pragma that causes automatic linking with correct library.

Alf P. Steinbach
Thanks Alf, when i say link i actually also mean being aware of the declarations in dll_B that is used in dll_A. suppose dll_B has a struct B_DATA that is the return type for A_function in dll_A, then is that also a bad design?
Jake