Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
545 views
in Technique[技术] by (71.8m points)

codeblocks - C++ undefined reference to WinMain@16 (Code::Blocks)

I'm learning C++ with Code::Blocks, and everytime i try to create a new class, I get an error message saying:

undefined reference to `WinMain@16'

Here's the code I've been using:

Main Class

#include "Lime.h"
#include <iostream>
using namespace std;
int main()
{
    Lime lime;
    return 0;
}

Lime Class (.ccp):

#include "Lime.h"
#include <iostream>
using namespace std;
Lime::Lime()
{
    cout<<"Hi!";
}

Lime Header (.h):

#ifndef LIME_H
#define LIME_H
class Lime
{
    public:
        Lime();
};
#endif

If someone knows, how to fix it, please, tell me!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I just had the exact same problem working with the exact same tutorials.

How to solve this? I found that restarting CodeBlocks gets rid of this error. It has nothing to do with how you created the files or any of your syntax. A restart does the trick.

Why does this occur? If I had to take a wild guess, I would think that CodeBlocks does indeed create the header/cpp files, it does not however link them to your project in a proper way that makes them usable (although it does ask you to link them to the project after you create them). This is a guess.

I understand that some people have commented on this by saying that you're creating a Windows GUI console application instead of a console application, but this is not the case. I too was creating a simple console application as Bucky explains in the videos.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...