Reputation: 1008
I just made a small program to tests some differences between java and C++ inheritance. It compiles but I get a problem when linking:
mingw32-g++.exe -o bin\Release\Tests2.exe obj\Release\Exec.o -s -lmingw32
c:/program files/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/../../../libmingw32.a(main.o):main.c:(.text.startup+0xa7): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
1 errors, 0 warnings (0 minutes, 0 seconds)
I've no ides where it comes from. I'm compiling a console app, not a GUI app, plus my main method is well formed:
class Exec{
public:
int main( int argc, const char* argv[] ){
Operation* op1=new Operation("add");
Operation* op2=new Operation("rest");
MyExtend* ext=new MyExtend(6,4, op1);
MyExtend* ext2=new MyExtend(6,4, op2);
cout << ext->getSum()->getValue() << endl;
cout << ext2->getRest()->getValue() << endl;
return 0;
}
};
I tried adding -lmingw32 but it doesn't work either (it shouldn't be added anyway). All the answers I found are referencing the GUI and main problem, but this is not the case. Any ideas?
All the best.
Upvotes: 1
Views: 1043
Reputation: 1
The bigest difference of java and cplusplus is you must write program entry by your self and also it is must c compatiple,so main is needed ,winmain is windows special, check your link flags is there a windows subsystem link flags ,chang it to console,it will be ok then.
Upvotes: 0
Reputation: 2023
In C++, main function is the entrance of the program, you should write it separately, not in the class.
Upvotes: 2