Friday 23 December 2016

c++ - Visual studio unit testing a static library; prevents additional dependencies in main project



I have a project that I would like to unit test in Visual Studio 2013. I have changed the project type to a static library (lib) after getting some linker errors and reading the answer to this question.



I do not understand the underlying mechanisms of compiling and linking in c++. In changing my project to a static library, it seems I have lost the ability to specify additional dependencies, which is a pain because I need three libs for my main project that I would like to test.



What should I do to test this project, is there a way to make my project a static library and still specify additional dependencies?


Answer



Static library is a collection of object files. No linker involved. Dependencies are not being resolved. It only requires headers to build.




Now, when you finally create an executable (or a dynamic library), you should link all the necessary dependencies.



However, note that additionally to the "classic" build process described above, Visual Studio IDE provides abstractions (convenient, but sometimes a bit misleading, especially for novices), called "Project references" and "Project dependencies". There are options to make a static library "depend" on other static libraries. Also, executable can depend on that first static library. When "Link dependencies" is enabled, Visual Studio will resolve entire dependency chain recursively and link all the necessary into your executable.



See also:




No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...