简体   繁体   English

无法在 eclipse 中编译 googletest

[英]unable to compile googletest in eclipse

I am trying to compile googletest (git clone https://github.com/google/googletest.git -b release-1.11.0) but keep getting 1000+ linker errors.我正在尝试编译 googletest (git clone https://github.com/google/googletest.git -b release-1.11.0) 但不断收到 1000+ Z3175B426046787EECE2377783 错误。

I am running windows 10, eclipse CDT (latest), mingw (latest) gcc.我正在运行 windows 10、eclipse CDT(最新)、mingw(最新)gcc。 I created an eclipse c++ project (executable, empty project).我创建了一个 eclipse c++ 项目(可执行,空项目)。

added include paths to:添加了包含路径:

  • googletest谷歌测试
  • googletest/includes谷歌测试/包括
  • googlemock谷歌模拟
  • googlemock/includes googlemock/包括

added source location to:将源位置添加到:

  • googletest/src谷歌测试/src
  • googlemock/src谷歌模拟/src

All is compiled without problems, but linking fails with 1000+ errors.所有编译都没有问题,但链接失败并出现 1000 多个错误。 Eg.例如。

C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
googletest\gtest.o: in function `testing::IsNotSubstring(char const*, char const*, wchar_t const*, wchar_t const*)':
C:\dev\unode\eclipse\unit_tests\Debug/../../googletest/googletest/src/gtest.cc:1821: multiple definition of `testing::IsNotSubstring(char const*, char const*, wchar_t const*, wchar_t const*)';
googletest\gtest-all.o:C:/dev/unode/eclipse/googletest/googletest/src/gtest.cc:1821: first defined here
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
googletest\gtest.o: in function `testing::IsSubstring(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&)':
C:\dev\unode\eclipse\unit_tests\Debug/../../googletest/googletest/src/gtest.cc:1827: multiple definition of `testing::IsSubstring(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&)';
googletest\gtest-all.o:C:/dev/unode/eclipse/googletest/googletest/src/gtest.cc:1827: first defined here
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
googletest\gtest.o: in function `testing::IsNotSubstring(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&)':

I am reading googletests readme.md to figure out what I am doing wrong but getting nowhere.我正在阅读 googletests readme.md 以找出我做错了什么但一无所获。 Some help would be greatly appreciated一些帮助将不胜感激

Ah, there is a file googletest/src/gtest-all.cc啊,有一个文件 googletest/src/gtest-all.cc

which includes all source files.其中包括所有源文件。 so all source files are compiled twice, deleting this file solves my problem所以所有源文件都编译了两次,删除这个文件解决了我的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM