visual studio - Google tests don't work with class in other project in solution -
i'm trying test simple class building (that has constructor).
file testclass.h
#pragma once class testclass { public: testclass(); };
file testclass.cpp
#include "testclass.h" testclass::testclass() { }
and add new project in solution: tests
. project contains 1 file.
file test.cpp
#include <gtest/gtest.h> #include "../example/testclass.h" test(test0, all) { expect_eq(true, true); } /* test(test1, part1) { testclass t; }*/ int main(int argc, char* argv[]) { testing::initgoogletest(&argc, argv); return run_all_tests(); }
if build code - (and tests). if uncomment commented block - have such output error:
1>------ rebuild started: project: example, configuration: debug win32 ------
1> testclass.cpp
1> example.vcxproj -> d:\alex\documents\visual studio 2015\projects\tests\debug\example.lib
2>------ rebuild started: project: tests, configuration: debug win32 ------
2> test.cpp
2>test.obj : error lnk2019: unresolved external symbol "public: __thiscall testclass::testclass(void)" (??0testclass@@qae@xz) referenced in function "private: virtual void __thiscall test1_part1_test::testbody(void)" (?testbody@test1_part1_test@@eaexxz)
2>d:\alex\documents\visual studio 2015\projects\tests\debug\tests.exe : fatal error lnk1120: 1 unresolved externals
========== rebuild all: 1 succeeded, 1 failed, 0 skipped ==========
i added gtest.lib
file dependency of linker input of tests
project.
added example
project dependency of tests
project.
built example
project static library (.lib).
if delete constructor testclass
- good.
project can find here.
i'm using microsoft visual studio 2015 update 3 on windows 10 pro x64.
google test framework version 1.8.0.
how can solve compilation problem? need constructor.
i can solve problem:
manually add builddir
(to me $(solutiondir)$(configuration)\
) way:
tests
properties -> configuration properties -> linker -> general -> additional library directories
, manually add example.lib
dependency way:
tests
properties -> configuration properties -> linker -> input -> additional dependencies
Comments
Post a Comment