LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-29-2018, 06:11 PM   #1
bkelly
Member
 
Registered: Jan 2008
Distribution: Centos 7-4
Posts: 137

Rep: Reputation: 11
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.

Last edited by bkelly; 04-02-2018 at 12:21 PM. Reason: show resolution
 
Old 03-30-2018, 11:48 AM   #2
Mill J
Member
 
Registered: Feb 2017
Location: 127.0.0.1 Sweet 127.0.0.1
Distribution: Void, LFS, Haiku, Quirky on Rpi and many others
Posts: 876
Blog Entries: 2

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
Did you forget a },;,etc or something? If we can't see code we cant really help.
 
Old 03-30-2018, 12:23 PM   #3
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,568

Rep: Reputation: 1093Reputation: 1093Reputation: 1093Reputation: 1093Reputation: 1093Reputation: 1093Reputation: 1093Reputation: 1093
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
 
Old 03-30-2018, 01:38 PM   #4
Mill J
Member
 
Registered: Feb 2017
Location: 127.0.0.1 Sweet 127.0.0.1
Distribution: Void, LFS, Haiku, Quirky on Rpi and many others
Posts: 876
Blog Entries: 2

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
@bkelly I noticed you marked this thread solved. Could you explain how you solved it, in case someone else has the same problem?
 
Old 04-02-2018, 12:23 PM   #5
bkelly
Member
 
Registered: Jan 2008
Distribution: Centos 7-4
Posts: 137

Original Poster
Rep: Reputation: 11
Mill J,
Good point. I edited the OP and marked my comments as a resolution. Is that satisfactory?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP extension and multiple source files results in multiple definition of `XXX' error atelszewski.versades Programming 1 02-16-2016 08:54 AM
multiple definition of 'variable_name' eteck Programming 3 11-03-2010 05:42 AM
c++ : multiple definition of 'namespaceName' kpachopoulos Programming 2 03-10-2009 10:50 PM
multiple definition of lrios Programming 4 04-27-2008 10:19 PM
multiple definition ? lackluster Linux - Software 1 11-27-2003 05:29 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration