8

So I've always had to use the project's "Additional Include Directories" property to set relative paths to other (library) projects that I'm dependent on for a given solution.

So the solution structure is essentially:

My App.sln
-> My App.vcxproj
-> My Lib.vcxproj

What I want, is for My App project to automatically have the path to My Lib project files added as an entry in its "additional include directories" simply because My App is dependent upon My Lib.

I set the library / linkage dependency by adding it under "References" for My App, which beautifully means that My App will automatically link against My Lib's output .lib. PERFECT!

But... I don't see how to get the .h files from My Lib to be included into My App without manually specifying its path (or relative path) to My App project's "additional include directories" property.

I have lived with this for years, but I had to solve the linkage issue for a dependent dependent and found a very slick way to do that without having to touch project settings.

Which makes me think - surely there is a way to do the same for "project A is dependent on project B and hence should automatically search project B for #include references"

Am I out on wishful thinking limb? Or am I missing some great facility in VS?

Mordachai
  • 9,412
  • 6
  • 60
  • 112
  • 1
    I use a similar pattern, but if I'm not sure if it would be an answer to the question you asked, which introduces risks of filename collisions/ambiguity. Better to at least require #include which works pretty well if everything has the same root level, then headers in libname, and cpp files in a src folder. – Kenny Ostrom Mar 06 '18 at 20:39
  • This is a popular approach. But I'd prefer to have it based on included modules (projects) - as sometimes it is convenient to swap out two similar projects and not need to update every client - just change the included module and dependency in the solution. Or, that's what I would like, anyway! – Mordachai Mar 06 '18 at 20:44
  • I am also here to ask the same question but seems like it is not possible with pure VS. You can use CMake. (File/Open/Cmake...) – Burak Nov 26 '21 at 11:52

1 Answers1

1

This can be done through the Property Manager. Here's an article describing the process in detail: Managing dependencies in Visual Studio C++ projects with property files.

The short of it is: you create a custom property sheet for your library project, in which you add its include directories. (Make sure to use paths that will work from your application project). Then you reference that property sheet from your application project.

Once you have that setup you can make modifications to the property sheet and it will automatically update all projects that are referencing those properties.

You find the Property Manager under View -> Other Windows.


Here's the complete setup. Note the MyLibIncludes property sheet in the lower left, and also notice that MyLibIncludes is referenced from MyApp: enter image description here

Here's what the MyLibIncludes property sheet looks like with the include folder to MyLib added: enter image description here

And if we look at MyApp's properties you'll find that the include directories to MyLib have been added automatically through inheritance, because we referenced MyLib's property sheet from MyApp: enter image description here

nullbot
  • 31
  • 4