0

OS:x64 win7 sp1 with vs2017

I use vcpkg to install gtest, and then try to test it.

I create a dir and it has two files:

//main.cpp
#include <gtest/gtest.h>
int add(int a, int b){
    return a + b;
}
TEST(addTest, add){
    EXPECT_EQ(1, add(2, -1));
    EXPECT_EQ(5, add(2, 3));
}
int main(int argc, char *argv[]){
    ::testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TEST();
}

# CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
project(test)
find_package(GTest REQUIRED)
add_executable(main main.cpp)
target_link_libraries(main gtest)

Then I use cmake .. "-DCMAKE_TOOLCHAIN_FILE=C:/src/vcpkg/scripts/buildsystems/vcpkg.cmake" and cmake --build ., and here is the log:

C:\src\cmake-test\main.cpp(17): error C3861: “RUN_ALL_TEST”: 找不到标识符(can't find the identifier) [C:\src\cmake-test\build\main.vcxproj]
已完成生成项目“C:\src\cmake-test\build\main.vcxproj”(默认目标)的操作 - 失败。
已完成生成项目“C:\src\cmake-test\build\ALL_BUILD.vcxproj”(默认目标)的操作 - 失败。
生成失败。
“C:\src\cmake-test\build\ALL_BUILD.vcxproj”(默认目标) (1) ->“C:\src\cmake-test\build\main.vcxproj”(默认目标) (3) ->(ClCompile 目标) ->  C:\src\cmake-test\main.cpp(17): error C3861: “RUN_ALL_TEST”: 找不到标识符(can't find the identifier) [C:\src\cmake-test\build\main.vcxproj]

    0 个警告(warnings)
    1 个错误(errors)

已用时间 00:00:01.15

It seems that "RUN_ALL_TEST" is not be defined.

So how to solve the problem?

4

0 回答 0