Link error?

Hello everybody!

I've recently started programming in C++, so I don't know much about errors. I've just created a new program, but when I'm trying to execute the code, Dev-C++ (the compiler I'm using) shows 2 errors.

1
2
  [Linker error] undefined reference to `WinMain@16' 
  ld returned 1 exit status  


It doesn't show a location, so I don't know where the error is.
Does anybody know what this means?

- Ojima
Could you submit yours code which you think is causing the error, the whole file, or just the part the compiler points to?

Thanks.
It means your project settings are bad. ou need to pick whatever passes for just plain C++ code. No Win16 (Win16? Yikes - I presume you're not using a pre Windows 95 OS?) or other such settings.

Which version of Dev-C+pp are you using? If it's from here:

http://www.bloodshed.net/devcpp.html

please stop using it and get something else.
Last edited on
@Davichococat
It doesn't say in what line the code is, so I can't tell you where the mistake could be.

@Moschops
What Dev-C++ should I use then?
The mistake is that your project settings have told the linker that your code contains a WinMain16. It's not a line of your code causing the problem - it's that your code (and all the libraries it is looking in) doesn't contain what it's looking for.

Here is an article talking about not using Dev-C++ and giving some fine alternatives.
http://www.cplusplus.com/articles/36vU7k9E/
@Moschops
Okay, I'm now using Code::Blocks 10.5, but I'm still getting the same error,
undefined reference to `WinMain@16'

What should I do to fix this?
Let's see the code, and what compiler are you using?
Last edited on
@Moschops

Okay, here's the code:
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
42
43
44
45
#include <iostream>
#include <string>
using namespace std;

string aName[9] = "";
string aPassword[9] = "";
int lNumber, lPassword, aCurrent, aNumber, aStatus[9];

int Setup(){
    for (int i = 0; i < 9; i++)
    {
         aStatus[i] = 0;
    }
    aName[0] = "admin";
    aPassword[0] = "password";
    aStatus[0] = 3;
    aNumber = 1;
    return 0;
}

int dLogin();
int dVersiondata();

int dLogin()
{
    dVersiondata();
    cout << "Accounts\n";
    for (int i=0;i<9;i+=1)
    {
        if (aStatus[i] > 0)
        {
                      cout << i+1 << ". " << aName[i] << endl;
        }
    }
    cout << "11. Shut down\n";
    system("PAUSE");
    return 0;
};

int dVersiondata()
{
    system("CLS");
    cout << "AmijOS C++\n\tAlpha 0.0.1 - Copyright 2012 by OjimaProductions\n";
    return 0;
};


It should create a simple screen, it's not much yet. It's a program I first programmed in BASIC, but when I saw the limited possibilities in BASIC, I thought I might wanted to reprogram it in C++.

- Ojima
There's no main function. Where does your code start? Nowhere, because there's no main function. C++ programs start at main.
hmm, tried it, I renamed Setup to main (btw, thanks, didn't know that :))
Now I'm getting no more warnings or errors. Thanks!
(and now I see what a complete n00b I am...)

- Ojima
Topic archived. No new replies allowed.