J'ai construit Google Test à partir de la source sur Windows 10. J'essaie maintenant de créer une application utilisant la bibliothèque. Construire le programme avec Clake échoue pour une raison quelconque.
Edit // Il semble que Cmake ne lie pas correctement Google Test. Je reçois les mêmes résultats lorsque je supprimai les mêmes résultats lorsque je supprimai le Voici mon code (le programme échoue à l'appel à voici le sous-dossier tests CMAKELIST.TXT: p> cible_link_libraires (tests GTEST :: GTEST) CODE> Ligne du dossier Tests CMAKELIST.TXT. P>
attendre_eq code>): p>
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: tests\CanTest.o:C:\Users\mkkek\Documents\koodi\cppkirja\Advanced-CPlusPlus\Lesson1\Exercise01\project\CxxTemplate\Debug/../tests/CanTest.cpp:18: multiple definition of `main'; src\CxxTemplate.o:C:\Users\mkkek\Documents\koodi\cppkirja\Advanced-CPlusPlus\Lesson1\Exercise01\project\CxxTemplate\Debug/../src/CxxTemplate.cpp:32: first defined here
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: tests\CanTest.o:C:\Users\mkkek\Documents\koodi\cppkirja\Advanced-CPlusPlus\Lesson1\Exercise01\project\CxxTemplate\Debug/../tests/CanTest.cpp:11: undefined reference to `testing::Test::Test()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: tests\CanTest.o:C:\Users\mkkek\Documents\koodi\cppkirja\Advanced-CPlusPlus\Lesson1\Exercise01\project\CxxTemplate\Debug/../tests/CanTest.cpp:11: undefined reference to `testing::Test::~Test()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: tests\CanTest.o:C:\Users\mkkek\Documents\koodi\cppkirja\Advanced-CPlusPlus\Lesson1\Exercise01\project\CxxTemplate\Debug/../tests/CanTest.cpp:14: undefined reference to `testing::Message::Message()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: tests\CanTest.o: in function `TestBody':
C:\Users\mkkek\Documents\koodi\cppkirja\Advanced-CPlusPlus\Lesson1\Exercise01\project\CxxTemplate\Debug/../tests/CanTest.cpp:14: undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\mkkek\Documents\koodi\cppkirja\Advanced-CPlusPlus\Lesson1\Exercise01\project\CxxTemplate\Debug/../tests/CanTest.cpp:14: undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\mkkek\Documents\koodi\cppkirja\Advanced-CPlusPlus\Lesson1\Exercise01\project\CxxTemplate\Debug/../tests/CanTest.cpp:14: undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\mkkek\Documents\koodi\cppkirja\Advanced-CPlusPlus\Lesson1\Exercise01\project\CxxTemplate\Debug/../tests/CanTest.cpp:14: undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: tests\CanTest.o:C:\Users\mkkek\Documents\koodi\cppkirja\Advanced-CPlusPlus\Lesson1\Exercise01\project\CxxTemplate\Debug/../tests/CanTest.cpp:19: undefined reference to `testing::InitGoogleTest(int*, char**)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: tests\CanTest.o:C:/msys64/mingw64/include/gtest/internal/gtest-internal.h:516: undefined reference to `testing::internal::IsTrue(bool)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: tests\CanTest.o: in function `GetSetUpCaseOrSuite':
C:/msys64/mingw64/include/gtest/internal/gtest-internal.h:516: undefined reference to `testing::internal::GTestLog::GTestLog(testing::internal::GTestLogSeverity, char const*, int)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/include/gtest/internal/gtest-internal.h:516: undefined reference to `testing::internal::GTestLog::~GTestLog()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/include/gtest/internal/gtest-internal.h:516: undefined reference to `testing::internal::GTestLog::~GTestLog()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: tests\CanTest.o:C:/msys64/mingw64/include/gtest/internal/gtest-internal.h:531: undefined reference to `testing::internal::IsTrue(bool)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: tests\CanTest.o: in function `GetTearDownCaseOrSuite':
C:/msys64/mingw64/include/gtest/internal/gtest-internal.h:531: undefined reference to `testing::internal::GTestLog::GTestLog(testing::internal::GTestLogSeverity, char const*, int)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/include/gtest/internal/gtest-internal.h:531: undefined reference to `testing::internal::GTestLog::~GTestLog()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/include/gtest/internal/gtest-internal.h:531: undefined reference to `testing::internal::GTestLog::~GTestLog()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: tests\CanTest.o:C:\Users\mkkek\Documents\koodi\cppkirja\Advanced-CPlusPlus\Lesson1\Exercise01\project\CxxTemplate\Debug/../tests/CanTest.cpp:13: undefined reference to `testing::internal::MakeAndRegisterTestInfo(char const*, char const*, char const*, char const*, testing::internal::CodeLocation, void const*, void (*)(), void (*)(), testing::internal::TestFactoryBase*)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: tests\CanTest.o:CanTest.cpp:(.rdata+0x210): undefined reference to `testing::Test::SetUp()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: tests\CanTest.o:CanTest.cpp:(.rdata+0x218): undefined reference to `testing::Test::TearDown()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: tests\CanTest.o:CanTest.cpp:(.rdata+0x278): undefined reference to `testing::Test::SetUp()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: tests\CanTest.o:CanTest.cpp:(.rdata+0x280): undefined reference to `testing::Test::TearDown()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: tests\CanTest.o: in function `RUN_ALL_TESTS()':
C:/msys64/mingw64/include/gtest/gtest.h:2473: undefined reference to `testing::UnitTest::GetInstance()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/include/gtest/gtest.h:2473: undefined reference to `testing::UnitTest::Run()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: tests\CanTest.o: in function `testing::AssertionResult testing::internal::CmpHelperEQ<int, int>(char const*, char const*, int const&, int const&)':
C:/msys64/mingw64/include/gtest/gtest.h:1528: undefined reference to `testing::AssertionSuccess()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: tests\CanTest.o: in function `testing::AssertionResult testing::internal::CmpHelperEQFailure<int, int>(char const*, char const*, int const&, int const&)':
C:/msys64/mingw64/include/gtest/gtest.h:1511: undefined reference to `testing::internal::EqFailure(char const*, char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)'
3 Réponses :
Vous pouvez incorporer le bâtiment de la bibliothèque GTEST (à partir de la source) directement dans la configuration de votre En d'autres termes, créez un nouveau fichier appelé puis dans votre fichier placer votre code de test dans Cumake code>, comme suggéré par la documentation Google officielle: https://github.com/google/googletest/tree/master/googletest#incorporant-into -An-existant-cmake-projet .
cmakelists.txt.in code>: p>
cmakelists.txt existant code>, incluez cet extrait: p>
Exemple.cpp code> devrait les rendre exécutables via
exemple.exe code> une fois construit. p> p>
J'ai rencontré ce même problème à l'aide de Eclipse. Le mien devait ne pas relier les bibliothèques de test Google que vous trouverez dans le dossier LIB du répertoire de build Google Test. P>
Pour autant que je sache, vous mettez les tests dans
tests code> exécutable. Mais les erreurs proviennent de la construction
cxxtemplate code> exécutable, qui contient non seulement
src / cxxxtemplate.cpp code>, mais
cantest.cpp code> aussi. Votre projet est désespéré en quelque sorte ... Oh, selon votre réponse, ce n'est pas un projet CMAKE qui est en fait construit. Agréable.