Lately, I’ve gotten some weird linker errors.
I’ve been taught that there’s two ways to work with libraries:
via
Project Properties > VC++ Directories > Include Directories
Project Properties > VC++ Directories > Library Directories
or via
Project Properties > C/C++ > General > Additional Include Directories
Project Properties > Linker > General > Additional Library Directories
Project Properties > Linker > Input > Additional Dependencies
Lately, sometimes when I use the VC++ Directories way, I get a linker error saying that there’s no definition for some function. When I add the library file that the function definition is in to the Additional Dependencies, it suddenly finds it.
But if you use VC++ Directories, normally you’re not supposed to use Additional Dependencies at all, right?
This has happened multiple times now and has left me more than confused. It worked fine on past projects, but not anymore. Sometimes the VC++ way even work on another PC, but not on mine.
I have always worked with VS2010, and am still working with VS2010.
Does anyone have a clue what’s going on?
Even though you specified the additional include directories, Visual Studio does not automatically try to link all library files present when you build your project. You must take the additional step of adding the library file name to your additional dependencies list. The additional include directories only helps to avoid writing the whole file path in your additional dependencies list.
An alternative to modifying the additional dependencies list is to use the #pragma directive. Specifically, use
This will direct the linker to link that file in your build.