我正在尝试使用使用测试驱动开发的现代C ++编程,并且这样做本书指示读者安装
谷歌模拟1.6。我试图从here下载源代码。然后根据我的书:
mkdir build
cd build
cmake ..
make
myComputer:build me$ cmake ..
-- The CXX compiler identification is AppleClang 8.0.0.8000042
-- The C compiler identification is AppleClang 8.0.0.8000042
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
CMake Error at CMakeLists.txt:56 (add_subdirectory):
add_subdirectory given source "../gtest" which is not an existing
directory.
CMake Error at CMakeLists.txt:61 (config_compiler_and_linker):
Unknown CMake command "config_compiler_and_linker".
-- Configuring incomplete, errors occurred!
See also "/Users/me/Downloads/googlemock-release-1.6.0 3/build/CMakeFiles/CMakeOutput.log".
确实缺少../gtest目录。因为这些是目录:
CHANGES COPYING build include scripts
CMakeLists.txt Makefile.am build-aux make src
CONTRIBUTORS README configure.ac msvc test
这些说明增加了混淆:
You will also need to build Google Test, which is nested within Google Mock.
cd $GMOCK_HOME/gtest
mkdir mybuild
cd mybuild
cmake ..
make
我查看了自述文件,但我似乎无法解决此问题。任何帮助/指导都是超级的!
答案 0 :(得分:0)
正如您所看到的here,Google Mock已经被GoogleTest project所吸引。
有多种方法可以安装GoogleTest,如The GoogleTest Readme中所述。由于您似乎正在使用CMake,我建议您按照
下的步骤操作加入现有的CMake项目
您还可以将应该放入CMakeLists.txt的所有内容放入CMakeLists.GTest,然后只将include(CmakeLists.GTest)
放入CMakeLists.txt。
如果您想确定应合并的固定版GoogleTest,可以在CMakeLists.txt.in中使用GIT_TAG
例如release-1.8.0´ instead of
master`。
在您的项目中加入GoogleTest后,您可以通过创建包含Foo
和gtest/gtest.h
的FooTest.cpp来为类Foo.h
添加gtests。因此,您还必须将add_executable(FooTarget FooTest.cpp)
和target_link_libraries(FooTarget gtest)
放入相应的CMakeLists.txt。
您还可以找到对此的简短说明,以及如何在these slides上将GoogleTests集成到ctest中。
答案 1 :(得分:0)
您需要在gmock目录中包含gtest。 我最初遇到的错误与您相同,而不是从https://github.com/google/googletest获得gtest版本1.6,并将其放置在gmock根目录中并成功构建了它。