[英]error: 'int main(int, char**)' previously defined here in C++
I'm implementing gtest now, and it gives me an error : main previously defined here. 我现在正在实现gtest,它给了我一个错误:main先前在这里定义。
Here's utest.cpp 这是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();
}
And here's the code that i'm testing test.cpp 这是我正在测试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;
}
There's nothing in test.cpp main but actual code will have some codes in main. test.cpp main中没有任何内容,但实际代码中的main中将包含一些代码。
I dont have header files for utest and test cpp files 我没有用于utest和测试cpp文件的头文件
I tried 我试过了
#ifndef UTEST_H
#define UTEST_H
and didn't solve the error. 并没有解决错误。
The error message states what the problem is, you have two main()
functions. 该错误消息指出了问题所在,您有两个
main()
函数。 I believe you want to remove the duplicate main()
from test.cpp. 我相信您想从test.cpp中删除重复的
main()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.