Error: ld returned 1 exit status

Hey all,

still kinda new to C++ . I'm learning basics from tutorial and getting error I shouldn't be getting. I left @ where the error occurs. It says "First defined here. Error: ld returned 1 exit status". I seem to have the example code correct. At least looks same to me. Can you see something I can't ? Any feedback much appreciated.

1
2
3
4
5
6
7
8
9
10
  using namespace std;

int add(int x, int y);

int main()
{@

    cout << "The sum of 3 and 4 is: " << add(3, 4) << endl;
    return 0;
}


and this is my add.cpp:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>

using namespace std;

int add(int x, int y) {

    return x + y;
    }

int main()
{

}
Last edited on
Looks like you defined main() twice.

File add.cpp should not have int main(). Delete lines 10 to 13.

In this case it doesn't need lines 1 and 3 either.
add.cpp could be simply
1
2
3
4
int add(int x, int y) {

    return x + y;
}


Dude ! You saved my life ! Haha !

It didn't occur to me that the second main() in add.cpp might be an issue since it's empty and C++ ignores empty objects. At least that's what I thought.

THANK YOU SO MUCH MAN ! ! !

Works nicely now .....
Topic archived. No new replies allowed.