错误:先前在C++中定义的'int main(int,char**)'

Lea*_*nne 0 c++ program-entry-point compiler-errors googletest redefinition

我现在正在实现gtest,它给了我一个错误:主要在此定义.

这是utest.cpp

// Bring in my package's API, which is what I'm testing
#include "../src/test.cpp"
// Bring in gtest
#include <gtest/gtest.h>

// Declare a test
TEST(TestSuite, testCase1)
{
     EXPECT_EQ(5,getX(5));
}

// Run all the tests that were declared with TEST()
int main(int argc, char **argv){
    testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}
Run Code Online (Sandbox Code Playgroud)

这是我正在测试test.cpp的代码

#include "ros/ros.h"
#include "std_msgs/String.h"
#include <Project2Sample/R_ID.h>
#include <geometry_msgs/Twist.h>
#include <nav_msgs/Odometry.h>
#include <sensor_msgs/LaserScan.h>


#include <sstream>
#include "math.h"

int getX(int x)
{
    return x;
}

int main(int argc, char **argv)
{
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

test.cpp main中没有任何内容,但实际代码将在main中包含一些代码.

我没有utest和测试cpp文件的头文件

我试过了

#ifndef UTEST_H
#define UTEST_H
Run Code Online (Sandbox Code Playgroud)

并没有解决错误.

Bla*_*ace 6

错误消息说明问题所在,您有两个main()功能.我相信你想main()从test.cpp中删除副本.