Find how to get this error

I have another challenge: write code that compiles perfectly but then gives this linker error:
Main.obj : fatal error LNK1179: invalid or corrupt file: duplicate COMDAT '_main'

Hint: Use main twice differently. Note that you will get a compiler error if you try to overload main. Removing the second or first use of main should end up calling main twice (meaning it compiles and links, and runs)
Last edited on
Which "compiler" are you using?
The Visual C++ 2008 Express Edition compiler. I'm not sure whether the compiler matters, just a similar error message should suffice.
In C::B if I call main inside main it compiles and runs, but crashes..
closed account (zwA4jE8b)
Got me...
but thats not too hard to do.
I can call main in main and get a stack overflow but thats about it.
Haha, infinite recursion is not considered a compile error unless you have infinite recursion templates. This challenge does not involve recursion ;)
closed account (zwA4jE8b)
1>forum-help.obj : error LNK2005: _main already defined in f.obj
1>C:\Visual Studio 2010\C++\forum-help\Debug\forum-help.exe : fatal error LNK1169: one or more multiply defined symbols found

.. getting closer only 10 error messages away, lol

EDIT: Don't know enough about linking
Last edited on
Neither do I, I just wrote some code to see what would happen and I got the linker error ;)
Hint: I only used one .cpp file and I only included <iostream> (it would still work without including iostream)
Last edited on
closed account (zb0S216C)
All I've managed to get was an access violation when returning from main (all I defined was a single integer (non-allocating)). LOL.

Wazzak
I think I'll post the solution:
1
2
3
4
5
6
7
8
9
10
template<typename T>
int main()
{
	cout << "Hello, World!" << endl;

	cin.sync();
	cin.ignore();
}

int RunMainFunction = main<void>() + main<unsigned>();
If you comment out one of the two calls to main for the global variable, it will compile and link fine.
error: cannot declare '::main' to be a template
error: ISO C++ forbids taking address of function '::main'
Huh, what compiler are you using? It compiles perfectly in Visual C++ 2008 Express Edition.
That's not valid C++ since you cannot overload the main function.
Apparently VC++ fails to recognize this, so it leaves it to the linker to pick up the pieces.
Topic archived. No new replies allowed.