使用Code :: Blocks在C ++应用程序中未定义引用`WinMain @ 16'

时间:2013-12-04 01:25:50

标签: c++ linker codeblocks

我刚刚制作了一个小程序来测试java和C ++继承之间的一些差异。它编译但链接时出现问题:

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)

我不知道它来自哪里。我正在编译一个控制台应用程序,而不是GUI应用程序,而且我的主要方法已经很好了:

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;
}

};

我尝试添加-lmingw32,但它也不起作用(无论如何都不应该添加)。我发现的所有答案都引用了GUI和主要问题,但事实并非如此。有任何想法吗?

一切顺利。

2 个答案:

答案 0 :(得分:2)

在C ++中,main函数是程序的入口,你应该单独编写,而不是在类中。

答案 1 :(得分:0)

java和cplusplus的最大区别在于你必须自己编写程序入口并且它必须是兼容的,所以需要main,winmain是windows special,检查你的链接标志是否有windows子系统链接标志,chang它到控制台,那就没关系了。

相关问题