please i have a little problem creating a class and making it run. The class is created separately as a header file with it's source code.
whenever i build the source code of the class, i get an error that says: undefined reference to 'WinMain@16'. And whenever I run the main, it gives me the error: undefined reference to 'samclass::samclass'

here's my code


#include "samclass.h"
using namespace std;

int main(){
  samclass obj;

return 0;}


#ifndef SAMCLASS_H
#define SAMCLASS_H
#include <iostream>
using namespace std;

class samclass
        void printcrap();


#endif // SAMCLASS_H

header source code

#include "samclass.h"
#include <iostream>
using namespace std;
void samclass::printcrap(){
cout<<"this is the real crap"<<endl;

I need help.

3 Years
Discussion Span
Last Post by samson.dadson.3

You don't compile each module down to *.exe, but instead just to object module then use the linker to link both object modules together at the same time. And you should be creating a console project, not a Windows project. The error you posted indicates you created the wrong kind of project.

Edited by Ancient Dragon


You need to ensure that all 3 files will be included in your project. You have to set it up so that first samclass.cpp is compiled, creating samclass.o. Then main is compiled. When main compiles and sees samclass.h with undefined functions it will look for the object file and use it.

From your title it looks like you might be using Code::Blocks. If this is the case you should create a project and select Project->Add Files to ensure that all 3 files are accounted for.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.