LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Eclipse multiple definition of main (https://www.linuxquestions.org/questions/programming-9/eclipse-multiple-definition-of-main-4175626627/)

bkelly 03-29-2018 06:11 PM

Eclipse multiple definition of main
 
Novice
Ubuntu 16.04, Eclipse Helios Service Release 2
I had a simple working UDP echo server running (copied from a tutorial) and added some code to exit gracefully. After getting the syntax correct, had several errors as I worked through it, Eclipse now complains: multiple definition of ‘main’

No other errors or warnings or informational flags.

This is a single app, Project Explorer shows a single app. Have not even tried two apps in one project. Do a find for “main” and it is only in one place. The matching UDP client app is in a completely different project. Exited and restarted Eclipse and even rebooted to no avail.

What can be done to get Eclipse to tell me where it finds the other “main”? How can this be corrected?

Edit: in the C/C++ Projects there are three items:
udp_client_simple
udp_client_very_simple
udp_server_very_simple

Might those be causing the problem? I don't see a method to remove them from this window. Right click and delete wants to delete the whole thing, which I do not want. The option "Remove from Context" is greyed out.

I screwed up and accidently deleted everything while trying to fix this. I did notice that a copy of the client code managed to sneak into the project. That might be the source of the second "main" But Eclipse would not tell me so.
I will mark this resolved and would prefer to delete the entire thread since no definitive answer can be produced now.

If you, dear reader, are a moderator and can delete this thread, please do so. I do not see a delete option.

Resolution:
I believe I looked at a file from another project to copy a some code into this project, then accidently saved it. That created two files with main(). When I did a search for "main" it only found one instance.

I presume (weakly) that is because the second file is not part of the project. I used ctl-F for the find. When I used that just now I see that there is no scope for the find. (For example, Nothing that restricts the scope of the to just this file, just this project, or all open projects. So I presume the find looks in all open files.)

I put the resolution here in the OP so the reader does not need to scan through many posts to find the answer.

Mill J 03-30-2018 11:48 AM

Did you forget a },;,etc or something? If we can't see code we cant really help.

NevemTeve 03-30-2018 12:23 PM

You have to know that these user-friendly IDE-tools make the programmers work quick and easy.
In reality, they make simple things complicated, and they don't give you a fair chanche to find out what's actually happening.
So I suggest you write your first programs in a simple text-editor like mcedit, and compile them with gcc:
Code:

cd ~
mkdir mytest
cd mytest
mcedit test1.c
gcc -o test1 -Wall -W -Werror -g test1.c
./test1


Mill J 03-30-2018 01:38 PM

@bkelly I noticed you marked this thread solved. Could you explain how you solved it, in case someone else has the same problem?

bkelly 04-02-2018 12:23 PM

Mill J,
Good point. I edited the OP and marked my comments as a resolution. Is that satisfactory?


All times are GMT -5. The time now is 11:31 AM.