0

Let's say I have such project structure

|-- DynamicLoader
|   `-- dmc
|       |-- DynamicLoader.h
|       |-- Loader
|       |   |-- DynamicLibrary.cpp
|       |   |-- DynamicLibrary.h
|       |   |-- LibraryManager.cpp
|       |   |-- LibraryManager.h
|       |-- Utils
|       |   |-- Utils.h
|       |-- dmc.cpp
|       |-- dmc.h

where dmc.h is my pre-compiled header.
I want to use it for example in my source files located in Loader folder like this:
#include "dmc/dmc.h
but the intelisense complains about it and I have to use those semantics:
#include "../dmc.h"

is there anyway to achieve this in visual studio? I've seen one project that worked similarly to this but I couldn't figure it out by myself

Qizot
  • 1
  • 3
  • (I would) Set the the path to `DynamicLoader/` as include directory and make all `#include`s relative to this. As you want `#include "dmc/dmc.h"` that's probably what you intent also. (In this case, it's probably better to use `#include <>` instead of `#include ""`. If header files have unique names it shouldn't make a difference but it may make things more obvious for human readers.) Include paths can be defined in the property window of the project. (Please, consider the configuration. There are separate property sets for each configuration but you can set them all at once.) – Scheff's Cat Sep 17 '18 at 09:35
  • Is there a special option to tell the IDE to use relative paths? – Qizot Sep 17 '18 at 09:41
  • The C and C++ compilers of all times provide a command line arg. `-I` for setting an include base dir. which may be repeated to have more than one. (The order may be relevant as well.) The IDE just covers this fact by making it configurable in the property window. – Scheff's Cat Sep 17 '18 at 09:43
  • Are you aware about the difference of `#include <>` and `#include ""`? [Source file inclusion](https://en.cppreference.com/w/cpp/preprocessor/include). (Don't take the "implementation defined" too hard. I've never seen something else than "typical implementation" and it should be valid for VS as well. Otherwise I should've noticed in daily work...) – Scheff's Cat Sep 17 '18 at 09:44
  • Ok, I don't know how but when I changed include directory from DynamicLoader to $(ProjectDir) it works now, thanks for the reference as well, never too little information to read :) – Qizot Sep 17 '18 at 10:03
  • My VS is in German. So, I've to translate to English and I'm not sure whether I'm precise. In Properties, I have C/C++ - Common - Additional Include Directories. This is the property which feeds the `/I` arguments. (You can see it when changing to C/C++ - Command Line as it shows how property settings are actually passed to the compiler.) In Additional Include Directories, you may define multiple directories, separated by `;`. With multiple projects and proper project dependencies VS itself will consider this also. – Scheff's Cat Sep 17 '18 at 10:09
  • `$(ProjectDir)` is a kind of variable (like an environment variable). If you click the arrow button at end of input field for Additional Include Directories, then item Edit... you get an editor window with a button Macros>>. Clicking the latter displays all available `$()` variables and their current settings. – Scheff's Cat Sep 17 '18 at 10:12

0 Answers0