undefined reference to `WinMain@16'

Apr 23, 2014 at 5:50pm
Hi, i am super noob in c++ programming
i actually don't have a programming question yet, but a lot of compiler problems and it is just one of them.

I installed codeblock 13.12 mingw32 in window 8,
it runs ordinary code like "hello world" very well.
But when i create class, it doesn't run anything.

thank you all

This is the Build Log

-------------- Build: Debug in classing (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -Wall -fexceptions -g -I -c D:\class\classing\class1234.cpp -o obj\Debug\class1234.o

c:/program files (x86)/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 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))



I have search a lot of thread but those solution dont fit my problems.
i guess there is something doesn't link to my header file, but have no idea how to link it.

i hope there is any clue that i can follow to solve my problems.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
  #ifndef CLASS1234_H
#define CLASS1234_H


class class1234
{
    public:
        class1234();
        virtual ~class1234();
    protected:
    private:
};

#endif // CLASS1234_H


#include <iostream>
#include "class1234.h"
using namespace std;

class1234::class1234()
{
    //ctor
}

class1234::~class1234()
{
    //dtor
}


#include <iostream>
#include "class1234.h"
using namespace std;

int main()
{
    cout << "Hello world!" << endl;
    return 0;
}
Apr 23, 2014 at 5:55pm
Your project is set up to be a Windows program and not a console program. You'll have to go in your project settings and change it to a console program.

I forget exactly how to do this in C::B, but probably just right-click on the project, go to properties, and look around for the option.
Apr 23, 2014 at 6:09pm
Create a new project with the Console Application template
Apr 23, 2014 at 6:19pm
In Code::Blocks the option to change this is under: Project -> Properties then select the 'Build Type' tab and look for the 'Type' drop-down box. Make sure to do this with both your Debug and Release versions.
Apr 24, 2014 at 6:03pm
Thank You for helping

i went to project-->properties-->build target--->type

it is still select as console application. then i run this again still the same problem.

-------------- Build: Debug in classing (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -Wall -fexceptions -g -I -c D:\class\classing\classc.cpp -o obj\Debug\classc.o
c:/program files (x86)/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 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))

Apr 24, 2014 at 6:24pm
and one more bit of information

In the headers folder
class.h shows grey, is that associate with any problem that cause me cant run the program.

http://eaglefairassetmanagement.com/wp-content/uploads/2014/04/c++-complier-problem.png
Apr 24, 2014 at 8:10pm
as long as it has been added to the project it should work. Test it...
Apr 24, 2014 at 10:21pm
Has anyone noticed that (as far as I can see) the error isn't in his program, but in the MinGW library itself:
libmingw32.a(main.o):main.c

The linker error is in libmingw32.a, in the file main.c - at the very least, @thomson's file is main.cpp...

I would suggest maybe reinstalling MinGW - try redownloading it or at least checking the md5 to see if it wasn't corrupted. You could also rebuild your project (the blue cycle button in the build bar, or F12 (I think)).

Also, the reason classc.h shows as grey is because it is header file - it doesn't get compiled. Files that won't be compiled are shown in grey, files getting compiled are shown in black. Just how Code::Blocks does it.
Last edited on Apr 24, 2014 at 10:23pm
Apr 24, 2014 at 10:47pm
Has anyone noticed that (as far as I can see) the error isn't in his program, but in the MinGW library itself


The error message is saying that libmingw32 is expecting a WinMain function and there isn't one.

So the error originates from the code that is calling that function (libmingw32). But the error is not caused by that code. It's caused by the function not existing.

So I don't think reinstalling MinGW will help.
Apr 26, 2014 at 12:17pm
Thank you for all your help

i just solve that crap from some way

if you have similar problem you can PM me for solution.

and i have question should we create a list of tutorial for how to use the compiler and what the options means and why do we use it?

for example, i have barely understanding on what is build script and why do we have it?


Apr 26, 2014 at 12:19pm
yeah and one more thing, if you guys like music, the Radio station Triple J is so awesome to listen to.

Topic archived. No new replies allowed.