简体   繁体   中英

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.

Here's 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

#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.

I dont have header files for utest and test cpp files

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. I believe you want to remove the duplicate main() from test.cpp.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM