0

My question is not answered by this question because I made a very different type of mistake, I now know. The project was incorrectly set up. It needed to be a console application for my purposes which it was not.

I am a new C++ programmer. I'm using Code::Blocks and working on Windows, and every time I try to add a class to my project, it begins returning this same error, even though it appears as if I'm telling my project where to build to (which was the solution suggested in this question).

Here is my attempted code:

main.cpp

#include <iostream>

using namespace std;

int main()
{
    cout << "Hello world!" << endl;
    return 0;
}

Monster.h

#ifndef MONSTER_H
#define MONSTER_H


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

#endif // MONSTER_H

Monster.cpp

#include "Monster.h"

Monster::Monster()
{
    //ctor
}

Monster::~Monster()
{
    //dtor
}
Community
  • 1
  • 1
Logan
  • 143
  • 1
  • 7
  • possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Captain Obvlious May 11 '15 at 01:01
  • New programmer. Checked that answer, too complex for my level of understanding. (Though if you specified the part I was supposed to look at...) – Logan May 11 '15 at 01:08
  • possible duplicate of [undefined reference to \`WinMain@16'](http://stackoverflow.com/questions/5259714/undefined-reference-to-winmain16) – Raymond Chen May 11 '15 at 01:14
  • possible duplicate of [undefined reference to WinMain@16 (codeblocks)](http://stackoverflow.com/questions/20020399/undefined-reference-to-winmain16-codeblocks) – Protomen May 11 '15 at 01:40
  • Guilherme, both files appear to be linked, so the answer to that question doesn't work for some reason. – Logan May 11 '15 at 01:44
  • This answers http://stackoverflow.com/a/27084740/1518921 and http://stackoverflow.com/a/20020411/1518921 They seem much like the chosen answer for you. Remember it is not why the author of another question chose a response that it is the correct one for you, you can view other answers to the same question. – Protomen May 11 '15 at 02:53
  • Yeah, I found other helpful answers too. It seems in the end that Code::Blocks also has some issues that weren't resolving on my computer. Trying a different compiler now. – Logan May 11 '15 at 03:26

1 Answers1

1

Seems like the project is configured as a Windows application rather than a console application.

Since you are using int main it will not know where to start.

You can set the entry point to int main function in the Code::Blocks additional linker options by adding '/entry:mainCRTStartup', or just as easily create a new console application workspace.

Cheers and hth. - Alf
  • 142,714
  • 15
  • 209
  • 331
woahguy
  • 261
  • 3
  • 13
  • This appears to have worked in the short term! I would swear on everything I know that I clicked console app, but the proof is in the pudding. Thank you for your help! – Logan May 11 '15 at 01:09
  • Okay, so more info...the error appears after I try adding a member function to the Monster class even if I started the project as a console application. – Logan May 11 '15 at 01:41
  • 1
    Note that the `/entry:` option is for Microsoft's linker, while in Code::Blocks one is most likely using g++ (and ld for linker). – Cheers and hth. - Alf May 11 '15 at 01:50
  • From personal experience, I know that CodeBlocks (with GCC) accepts a regular `main` function with a Windows subsystem. – chris May 11 '15 at 02:43