0

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.

nagates
  • 620
  • 13
  • 40

1 Answers1

0

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.

Sean Burton
  • 907
  • 7
  • 15
  • I think I understand what your saying, now I am just trying to think how to do that, without including the 3rd party header, in my header that gets exposed to the consumer of my dll. – nagates Sep 15 '17 at 14:57
  • 1
    @nagates, this is the question of splitting your code between h and cpp. h should contain only interface details, cpp - implementation. This could be helpful: https://stackoverflow.com/questions/843389/the-pimpl-idiom-in-practice – KonstantinL Sep 15 '17 at 15:00
  • @KonstantinL, if you put the implementation in the cpp file, then does a user of you create your type? You can include the interface header, but how does the consumer code know about the more specific class, that implements the interface (that uses 3rd party code). – nagates Sep 15 '17 at 15:25
  • Any concrete types used in the interface will also need to be included in the header provided to the user. This is the reason for the PIMPL idiom that @KonstantinL mentioned, when using PIMPL your interfaces will uses references/pointers wherever possible, so you can mainly just include forward declarations in the header. Though you will of course need to include complete definitions for any classes that the user will need to actually access (rather than just passing around to functions). – Sean Burton Sep 15 '17 at 15:28
  • I've heard of this PIMPL pattern, seems like I need to read a bit more into it to fully understand it. – nagates Sep 15 '17 at 15:29