I am trying to set up a multi-project solution using static libraries in Visual Studio.
As an example, the project OtherProject contains the class Foo situated in Foo.h, which I would like to use in the project MyProject.
From what I have understood, to accomplish this using static libraries I have to:
- In OtherProject change "Configuration Type" to "Static library (.lib)".
- In MyProject.
- In "Common Properties -> Framwork and Referencees" Add New Reference to OtherProject
- In "VC++ Directories"
- In "Include Directories" add path to OtherProject's header files.
- In "Library Directories" add path from OtherProject to the created "OtherProject.lib".
In "Input>Additional Dependencies" add "OtherProject.lib".(Edit) This step appears to be unnecessary and is made implicitly during 2.1 (thanks to @JBentley for pointing it out).
"Solution Properties -> Common Properites -> Project Dependencies", chose MyProject in dropdown and add dependency to OtherProject.(Edit) This is unnecessary, and is made implicitly in step 2.1 (also @JBentley).
...and everything should be peachy. However, if I skip everything above and only include the source files of OtherProject, like this:
- In MyProject "VC++ Directories -> Include Directories" add path to OtherProject header files (and possible source files as well?).
...everything appears to be working like before, and with much less work.
My test file in MyProject looks like this:
#include <OtherProject/Foo.h>
int main()
{
Foo foo;
return 0;
}
Questions
- Does my "Static Library" approach appear to be valid, or may I run into problems later on?
- Is the second approach valid? Will it create problems later? I guess one cons is that I cannot hide part of the implementation in a lib file, and have to supply both source and header instead of lib and header.
- Is there any pros and cons of each methods?
(Edit) The following question is about a similar problem: Link libraries with dependencies in Visual C++ without getting LNK4006. It appears Visual Studio is smart enough to take care of some of some of the steps I listed, and avoiding the unnecessary steps appears to get rid of "LNK4006 second definition ignored" I was having further down the line: