Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio (C++)- what is the best practice regarding directories configurations?

(I'm using VS 2010 but most of the info is relevant at least down to VS 2003, perhaps with slight differences in the organization/layout of the build configuration menus\GUI)

When configuring a project build, there is a section named "VC++ Directories" that contains 6 labels. 2 of them are:

  1. Library Directories
  2. Include Directories

In addition, if you go to 'C/C++' -> 'Additional Include Directories' , you can specify additional directories, that AFAIK (from the descriptions of these directories in MSDN and VS help) is identical to 'Include Directories' (though there is probably some search order between them). Likewise, if you go to 'Linker' -> 'Additional Library Directories' you can specify additional paths for libraries to link with the project (here the description is more precise- "Allows the user to override the environment library path", so these paths are searched sooner).

My question is-

is there a reason to use one (of the paths) over the other? what is the best practice?

Please relate in your answer to using the property pages features (which adds flexibility to the configuration of different projects and allows to easily reuse existing ones but are causing me more confusing regarding the best practice here). Thanks in advance.

like image 714
infokiller Avatar asked Nov 06 '11 07:11

infokiller


People also ask

What is the project directory in Visual Studio?

When you create a new project, Visual Studio saves it to its default location, %USERPROFILE%\source\repos. To change this location, go to Tools > Options > Projects and Solutions > Locations. For more information, see Options dialog box: Projects and Solutions > Locations.

How do I change directories in Visual Studio?

If you've already installed it and want to change the location, you must uninstall Visual Studio and then reinstall it. In the Shared components, tools, and SDKs section, select the folder where you want to store the files that are shared by side-by-side Visual Studio installations.

How do I add additional directories in Visual Studio 2022?

Open the project's Property Pages dialog box. For details, see Set C++ compiler and build properties in Visual Studio. Select the Configuration Properties > C/C++ > General property page. Modify the Additional Include Directories property.

How do I change the build configuration code in Visual Studio?

Open the Configuration Manager dialog box. In the Active solution configuration drop-down list, select the configuration you want. In the Project contexts pane, for every project, select the Configuration and Platform you want, and select whether to Build it and whether to Deploy it.


1 Answers

Let's consider first only include paths.

The Microsoft documentation states that the compiler searches for directories in the following order:

  1. Directories containing the source file.

  2. Directories specified with the /I option, in the order that CL encounters them.

  3. Directories specified in the INCLUDE environment variable.

Now, the ["VC++ Directories" → "Include directories"] is documented as corresponding to the INCLUDE variable. I.e., these directories are searched last. According to the documentation.

And the ["C/C++" → "General" → "Additional Include Directories"] is documented as corresponding the /I option. I.e., these directories are searched first. According to the documentation.

Insofar as any best practice exists, it probably is

  • to leave open the possibility of overriding includes, and

  • to minimize the compiler invocation command line length (so as not to stress poor Windows – as I recall there was/is an 8 KB limit, or thereabouts).

I.e., use ["VC++ Directories" → "Include directories"] by default.


The complete set of environment variable correspondences:

  • ["VC++ Directories" → "Executable directories"] → PATH

  • ["VC++ Directories" → "Include directories"] → INCLUDE

  • ["VC++ Directories" → "Reference directories"] → LIBPATH (for #using)

  • ["VC++ Directories" → "Library directories"] → LIB


How did I find out this?

Simply by clicking in the GUI and pressing F1 for help. :-)

It's always a good idea to RTFM.

like image 196
Cheers and hth. - Alf Avatar answered Sep 23 '22 10:09

Cheers and hth. - Alf