views:

79

answers:

2

Can anyone tell me what the file "/usr/include/c++/4.4/exception" would have to do with this error. There is no main defined in that file. I am not sure how to read the error message.

./libfoo.a(main.o): In function `main':
/usr/include/c++/4.4/exception:62: multiple definition of `main'
interface-wx/App.o:/usr/include/c++/4.4/exception:62: first defined here
collect2: ld returned 1 exit status

Any help would be greatly appreciated.

+2  A: 

Well, like it says. there are multiple definitions of 'main'. check these two files. main.cpp and interface-wx/App.cpp.

claws
@claws: thanks for your help. There are multiple definitions of main, one in each of those files. If I comment out the one in interface-wx/App.cpp, nothing changes when I link. If I comment out the one in main.cpp everything links fine but the program doesn't run when I execute it. I just get an error. That is why I was trying to figure out whether or not the "exception" file I mentioned above could have anything to do with it. P.S. This is wxWidgets program that used to link fine with wxWidgets 2.8.6 but now having this issue when linking with wxWidgets 2.9.1.
csmithmaui
Since, you didn't show the programs. I've no idea about why those programs aren't running. But my guess would be. App.cpp might be displaying the GUI and main.cpp would be doing the actual task you want to accomplish. If thats the case. Then you are programing it wrong. find some tutorials/examples on using wx-widgets over net. Bottom line is, Your complete project must contain only single definition of main. You need to adjust your code appropriately to make it work. Commenting out is not a solution.
claws
Just to clarify, interface-wx/App.o was being created from a file called App.cc one directory above(which is what was supposed to happen according to the original writer's). I was getting confused because there was also a interface-wx/App.cc that defined a main also but doesn't get compiled anymore. I assume it was used for testing. That's why nothing changed when I commented out main in that file for testing.
csmithmaui
A: 

So I figured out what was going on...just in case someone else runs into this. A good way to find out where that duplicate definition is coming from in your code is to use the command:

nm -l name_of_object_file.o

nm is used to print the symbol table of an object file. I piped the output to a file and searched for main. The -l switch will print out line numbers for the symbols. This allowed me to see where that other pesky main definition was coming from.

For wxWidgets users:
The macro IMPLEMENT_APP(App) was defining a main for App when I really wanted it to use my main. The original code(which I didn't write) had a #define IMPLEMENT_WXWIN_MAIN at the top of the App file and as I said earlier, used IMPLEMENT_APP(App). Everything worked fine with wxWidgets 2.8.6, but when I tried to use wxWidgets 2.9.1, I started having this issue.

Solution:

Replace IMPLEMENT_APP(App) with wxIMPLEMENT_APP_NO_MAIN(App);

csmithmaui