53
votes

In C++, you got the header files (.h), the (.lib) files and the (.dll) files.

In Visual Studio, you provide the location to search for these files in three different places:

  1. Configuration Properties => C/C++ => General => Additional Include directories. Here you list out the "include" directories that you want searched and made available.

  2. Configuration Properties => Linker => General => Additional Library directories. Here you list out the "lib" directories that you want to be searched and made available.

  3. Configuration Properties => Linker => Input => Additional dependencies. Here you explicitly specify the .lib files that want to include.

The questions are:

Q1: If you have specified the header file in #1 and the lib in #2, why/when would you want to specify anything in #3?

Q2: I see people including a specific debug or release version of a lib in #3. Can you specify either the debug or the release version of a lib in #3 and still build in release or debug mode? Ideally, which version of the library debug/release should be provided here?

4

4 Answers

38
votes
  1. Configuration Properties => C/C++ => General => Additional Include directories. Here you list out the "include" directories that you want searched and made available.

This tells the compiler where to look for header files enclosed in angle brackets. This affects how the compiler (or preprocessor) does it's job.

  1. Configuration Properties => Linker => General => Additional Library directories. Here you list out the "lib" directories that you want to be searched and made available.

This tells the linker where to look for libraries (i.e., what directories to look in). This affects how the linker (rather than the compiler) does its job.

  1. Configuration Properties => Linker => Input => Additional dependencies. Here you explicitly specify the .lib files that want to include.

This tells the linker what libraries to look for in those directories. This also affects how the linker does its job.

Q1: Generally if you use 2, you almost certainly need to use 3 as well. 3 tells it what library to link with, and 2 tells it where to find that library. Of course, it can be more than one library as well.

Q2: If a debug and release library are both provided, you typically want to use the debug version in a debug build and the release version in the release build. At the top-left corner of the dialog you select which configuration you want to modify. Typically you'll want to specify directories for both debug and release, but specify individual libraries, one for debug and one for release.

4
votes

And just to point out the obvious, you don't have to add any .h files you are using in a properties setting of your project because you explicitly include them in your source code, which looks for the headers in the paths you have already provided.

2
votes

Also, in those above places, when you add in a directory, look at the MACROS>> button. e.g. you may want to use different libraries for 32bit/64bit/Release and Debug. You can use the ($ProjectDir) MACRO to give a relative link, and e.g. the ($DXSDK_DIR) MACRO to make sure you get the right libs for your directx development.

So I have ($DXSDK_DIR)\Lib\x86 and ($DXSDK_DIR)\Lib\x64 which also takes the problem away when moving between 32bit and 64bit Windows OS for development.

2
votes

Regarding your Q2...

For 3rd-party libraries, I take advantage of Visual Studio Build Command macro variables $(Platform) and $(Configuration) enter something like this:

Y:\dev3\cpp\cryptopp\cryptopp561\$(Platform)\Output\$(Configuration);...

In this way, you can just enter the same exact line and Visual Studio substitute the macro variables and look in either \cryptopp561\Win32\Output\Release\ or \cryptopp561\Win32\Output\Debug\ depending on which configuration you have active. It doesn't actually save much typing but it helps keep things consistent and accurate.