Creating c++ .lib project, consumer project has to reference the libs includes

38 views Asked by At

So I am pretty sure I am doing something wrong with my design/setup. But basically in visual studio, I want to create a .lib project that loosely wraps third party code, that part is simple enough.

However I am finding when I go to use lib in my other project (in this case a dll, could easily be an exe in a different proj, etc), the dll project is complaining that it needs the same include directories as the lib project. This seems...not helpful. I sorta get why it is showing the message, because I am including a header from my lib, that is in turn including the 3rd party include file...

Is there a better design suggestion for this? Or a better way to link the 2 projects in visual studio.

my consumer dll, does have my lib's include directory referenced, and I added the project as reference, so the lib output should be setup too.

to help visualize

3rd party code -> my wrapper lib -> my dll consumer.

does it seem like my consumer code should have to include the same header files that my my wrapper project is meant to abstract away.

1

There are 1 answers

5
Sean Burton On

I am including a header from my lib, that is in turn including the 3rd party include file...

This is the problem, of course it will need that header if you are trying to include that header, whether directly or indirectly through another header.

You should produce a new header for the user of your lib that contains only the functions you are exposing to the user, and that doesn't include any other functions or other headers for the internal functions you are trying to wrap. The user of your lib can then just include this header, which will contain all the definitions they need.