I have created a custom C++ Matrix
class and my intention is to write naive implmentations of some numerical algorithms (Root finding, linear solvers, interpolators) using this class.
I want to unit test my piece of code.
My header files Matrix.h
and MatrixX.h
containing the logic are in a project Matrix
. This project builds successfully, and the target is a DLL file.
My unit tests are in a test project MatrixUnitTest
. I have added the Matrix
project to this test project in Visual studio, as well added a reference to Matrix
.
I setup Project Properties > C/C++ > General > Additional Include Directories to have the path to the directory containing the header files Matrix.h
and MatrixX.h
.
I setup Project Properties > Linker > General > Additional Library Directories to have the \Debug folder containing my Matrix.dll file.
When I try to build the test project, I get a missing .lib file. But, I have a dynamic library, instead of a static one.
Error LNK1104 cannot open file 'D:\data\dev\quasar\cpp\MatrixUnitTest\Debug\Matrix.lib'
MatrixUnitTest D:\data\dev\quasar\cpp\MatrixUnitTest\LINK 1
If I explicitly add Matrix.dll
to Project Properties > Linker > Input > Additional Dependencies, it cannot open the file.
How do I properly have Visual Studio find my DLL during the build of the test project, so the linker can resolve the calls to the Matrix API?
Build Log.
1>------ Rebuild All started: Project: Matrix, Configuration: Debug Win32 ------
1>pch.cpp
1>dllmain.cpp
1>Matrix.vcxproj -> D:\data\dev\quasar\cpp\MatrixUnitTest\Debug\Matrix.dll
2>------ Rebuild All started: Project: MatrixUnitTest, Configuration: Debug Win32 ------
2>pch.cpp
2>MatrixUnitTest.cpp
2>D:\data\dev\quasar\cpp\Matrix\MatrixX.h(72,1): warning C4812: obsolete declaration style: please use 'MatrixX<scalarType>::MatrixX' instead
2>D:\data\dev\quasar\cpp\Matrix\MatrixX.h(72,1): warning C4812: obsolete declaration style: please use 'MatrixX<int>::MatrixX' instead
2>D:\data\dev\quasar\cpp\Matrix\MatrixX.h(72): message : while compiling class template member function 'MatrixX<int>::MatrixX(const MatrixX<int> &)'
2>D:\data\dev\quasar\cpp\Matrix\MatrixX.h(209): message : see reference to function template instantiation 'MatrixX<int>::MatrixX(const MatrixX<int> &)' being compiled
2>D:\data\dev\quasar\cpp\Matrix\MatrixX.h(94): message : while compiling class template member function 'MatrixX<int>::MatrixX(std::initializer_list<std::initializer_list<_Ty>>)'
2> with
2> [
2> _Ty=int
2> ]
2>D:\data\dev\quasar\cpp\MatrixUnitTest\MatrixUnitTest.cpp(16): message : see reference to function template instantiation 'MatrixX<int>::MatrixX(std::initializer_list<std::initializer_list<_Ty>>)' being compiled
2> with
2> [
2> _Ty=int
2> ]
2>D:\data\dev\quasar\cpp\MatrixUnitTest\MatrixUnitTest.cpp(16): message : see reference to class template instantiation 'MatrixX<int>' being compiled
2>LINK : fatal error LNK1104: cannot open file 'D:\data\dev\quasar\cpp\MatrixUnitTest\Debug\Matrix.lib'
2>Done building project "MatrixUnitTest.vcxproj" -- FAILED.
========== Rebuild All: 1 succeeded, 1 failed, 0 skipped ==========