未定义引用`WinMain @ 16'MinGW

时间:2016-02-24 15:51:50

标签: c++

最近开始尝试在C ++中创建DLL,并一直在尝试为命令行输入创建通用用户提示类。当我尝试编译代码时,我在.cpp中得到以下错误:

c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libmingw32.a(main.o):(.text.startup+0xa7): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status
make.exe": *** [userPrompt] Error 1

对错误进行一些阅读使我相信当文件中没有主函数时会发生这种情况 - 如果是这种情况,那么在尝试制作.cpp文件时如何避免这种情况在图书馆?

我当前的编译器是MinGW,我当前的IDE是NetBeans。

编辑:根据要求,编译的完整命令行日志 另外,undefined reference to `WinMain@16'(在答案中链接的副本中)在答案中暗示在.cpp文件中某处需要main或WinMain才能编译,这是上面提到的问题的一部分(而且我对不起,如果不清楚的话,如果实际情况确实如此,如果不是,我该怎样绕过这个限制呢?

g++     userPrompt.cpp   -o userPrompt
userPrompt.cpp:33:54: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]
         const string strCommands[2] = {"HELP", "QUIT"}; // Array of all valid commands.
                                                      ^
userPrompt.cpp:34:92: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]
         const string strHelpText[2] = {"to re-list these commands.", "to exit this prompt."}; // Parallel array of help texts for valid commands.
                                                                                            ^
userPrompt.cpp:38:17: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]
                 "==================================================\n";
                 ^
userPrompt.cpp:33:54: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
         const string strCommands[2] = {"HELP", "QUIT"}; // Array of all valid commands.
                                                      ^
userPrompt.cpp:34:92: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
         const string strHelpText[2] = {"to re-list these commands.", "to exit this prompt."}; // Parallel array of help texts for valid commands.
                                                                                            ^
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libmingw32.a(main.o):(.text.startup+0xa7): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status
make.exe": *** [userPrompt] Error 1

BUILD FAILED (exit value 2, total time: 504ms)

0 个答案:

没有答案