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

(I use VS 2010, but most of the information matters, at least until VS 2003, perhaps with slight differences in the organization / layout of the assembly \ GUI configuration menu)

When setting up the project assembly, there is a section called "VC ++ Directories" that contains 6 shortcuts. 2 of them:

  • Library catalogs
  • 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" (although between them, there is probably some search order). Similarly, if you go to 'Linker' β†’ 'Additional Library Directories' , you can specify additional paths for the libraries that will be associated with the project (here is a more accurate description). "Allows the user to redefine the environment library path," so these paths will be found earlier).

My question is

Is there a reason to use one (path) over another? What is the best practice?

Please tell us in your response to the use of properties of property pages (which adds flexibility to customize various projects and makes it easy to reuse existing ones, but causes me more confusion regarding best practices here). Thanks in advance.

+6
source share
2 answers

First, consider only the included paths.

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

  • Directories containing the source file.

  • Directories specified with the /I option in the order in which the CL encounters them.

  • Directories specified in the INCLUDE environment variable.

Now ["VC ++ Directories" β†’ "Include Directories"] is documented as matching the INCLUDE variable. Ie, these directories are viewed last. According to the documentation.

And ["C / C ++" β†’ "General" β†’ "Additional inclusion directories"] is documented as the corresponding /I option. I., these directories are searched first. According to the documentation.

Since there is some good practice, it’s probably

  • to leave the option to enable overrides, and

  • to minimize the length of the command line of the compiler call (so as not to be shy about bad Windows & ndash, since I remember that there was / was a limit of 8 KB or so).

Ie, use ["VC ++ Directories" β†’ "Include Directories"] by default.


A complete set of environment variable mappings:

  • ["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 about this?

Just press the GUI and press F1 for help. :-)

It is always a good idea for RTFM.

Cheers and hth.,

+4
source

By default, Visual Studio places the following paths in its INCLUDE variable (VC ++ Directories β†’ Include directories):

  • path to Microsoft Visual C ++ headers: $(VCInstallDir)include
  • path to MFC headers (for MFC projects): $(VCInstallDir)atlmfc\include
  • path to the Windows SDK headers: $(WindowsSdkDir)include;$(FrameworkSDKDir)\include

They are preconfigured and simply leave them where they are. If your project depends on some additional components / frameworks, add the paths to their headers in C / C ++ β†’ General β†’ Additional Include Directories ( /I ). In this case, use angle brackets with #include statements.

The same is for libraries - leave the default values ​​for Visual Studio and the path to the libraries from additional components / frameworks, add Linker β†’ Additional library directories in Linker.

0
source

Source: https://habr.com/ru/post/900873/


All Articles