【发布时间】:2016-02-06 13:51:38
【问题描述】:
我想将 gtest 包含到我的 C++ 项目中。我正在使用 Clion 作为 IDE,它应该可以工作。一些测试已经开始工作,但我无法使用 B_RocChoice.h 中的任何函数。它表示该函数未在此范围内声明。
谁能告诉我我做错了什么?我必须如何更改它识别我的方法的 CMakeLists.txt 文件?
这是我的basic_tests.cpp,我的测试用例将在这里编写。
这是我的Directory。
这里,最外面的CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project(cli)
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread")
set(SOURCE_FILES
include/A_WowbaggerChoice.h
include/AbstractChoice.h
include/B_RocChoice.h
include/C_CnnChoice.h
include/D_DetectorChoice.h
include/E_LearningChoice.h
include/Help.h
include/MyException.h
include/StartScreen.h
include/tinyxml.h
include/types.h
src/A_WowbaggerChoice.cpp
src/AbstractChoice.cpp
src/B_RocChoice.cpp
src/C_CnnChoice.cpp
src/D_DetectorChoice.cpp
src/E_LearningChoice.cpp
src/Help.cpp
src/main.cpp
src/MyException.cpp
src/StartScreen.cpp
tinyxml/tinystr.cpp
tinyxml/tinystr.h
tinyxml/tinyxml.cpp
tinyxml/tinyxml.h)
add_subdirectory(googletest)
add_executable(cli ${SOURCE_FILES})
target_link_libraries( cli ${OpenCV_LIBS} )
CMakeLists.txt 为gtest。
cmake_minimum_required(VERSION 2.6.2)
project( googletest-distribution )
enable_testing()
option(BUILD_GTEST "Builds the googletest subproject" ON)
#Note that googlemock target already builds googletest
option(BUILD_GMOCK "Builds the googlemock subproject" OFF)
if(BUILD_GMOCK)
add_subdirectory( googlemock )
elseif(BUILD_GTEST)
add_subdirectory( googletest )
endif()
add_subdirectory(basic_tests)
CMakeLists.txt 为basic_tests
include_directories($(gtest_SOURCE_DIR}/include
${getest_SOURCE_DIR}))
#include_directories(../../src/)
include_directories(../../include/)
add_executable(runBasicCli
basic_check.cpp)
target_link_libraries(runBasicCli gtest gtest_main)
#target_link_libraries(cli)
【问题讨论】:
-
你能先修复你的链接吗?
-
sry,作为新会员,我只能在一个帖子中发送2个链接
-
你能把问题降到最低吗?
-
希望你现在能更好地理解它
-
为什么要这样使用gtest&gmock?我以完全不同的方式使用它:我为我的 Visual Studio 版本构建了两个库,并将其放置在文件系统的某个位置(不在项目内部)和项目内部,我使用
find_package查找 gtest&gmock,它是在我看来要简单得多。