0

Recently started trying to create DLLs in C++ and have been trying to create a generic user prompt class for command line input. When I try to compile the code I get the following error in the .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

Doing some reading on the error led me to believe that this occurs when there's no main function in the file -- If this is the case how do I avoid this when trying to make a .cpp file for the purpose of putting it in a library?

My current compiler is MinGW and my current IDE is NetBeans.

EDIT: As requested, full command line logs for the compile Additionally, undefined reference to `WinMain@16' (As linked in the answer posted as a duplicate) implies in the answer that a main or WinMain is required somewhere in a .cpp file for it to compile, a part of the question asked above (And I'm sorry if this was unclear) is if that is actually the case, and if it is not how do I circumvent this restriction?

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)
Community
  • 1
  • 1
Sam Cros.
  • 1
  • 1
  • 1
    How do you use your compiler? Please show us the command line. – MikeCAT Feb 24 '16 at 15:52
  • If you're building a DLL, why is the name of the output file `collect2.exe`? – PaulMcKenzie Feb 24 '16 at 15:53
  • @PaulMcKenzie I guess `collect2.exe` is not the name of the output file but the name of the tool. – MikeCAT Feb 24 '16 at 15:54
  • Also, library generally refers to code you statically link to vs. shared library/DLL which is loaded dynamically at runtime and the necessary code may be different as well as the file extension. – crashmstr Feb 24 '16 at 15:54
  • @MikeCAT Updated the post with the full logs from the attempted compile. Also, if it's at all important, I'm using the NetBeans IDE. – Sam Cros. Feb 24 '16 at 16:04
  • 1
    I guess you should set the "project option" of your IDE to have it build a DLL. – MikeCAT Feb 24 '16 at 16:05

0 Answers0