header files creation undefined reference

I just started creating header files of my project but i quiet am not getting it right i use code blocks 16.0 currently i am stuck with " undefined reference "

here is the code

main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include "abc.h"
using namespace std;
int main()
{ abc p;
    system("cls");
   cout<<"\n\n\t OPENING HEADER FILE FUNCTION NOW ";
   p.something();
   return 0;
}


abc.h
1
2
3
4
5
6
7
8
#ifndef ABC_H
#define ABC_H
class abc
{ int a;
  public:
   void something();
};
#endif // ABC_H 


abc.cpp
1
2
3
4
5
6
7
#include "abc.h"
#include<iostream>
using namespace std;
void abc::something()
   {  a=5;
      cout<<"\n\t\t ...... IT WORKS ...... "<<a;
   }

error message
C:\TURBOC3\BIN\ASAP\MAIN.o :MAIN.cpp|| undefined reference to `abc::something()'|

please help me out....

learned this here---> http://www.cplusplus.com/forum/articles/10627/
Last edited on
Are you sure you're showing us the right code? I don't see anything trying to call a function called Read() anywhere in what you've posted.
You probably did not add abc.cpp to your project.
MikeyBoy
Are you sure you're showing us the right code? I don't see anything trying to call a function called Read() anywhere in what you've posted.

sry i edited the program but copied the older error message, changed it now.

coder777
You probably did not add abc.cpp to your project.

well the files are in the same file on my pc, if that may be causing the error.
well the files are in the same file on my pc, if that may be causing the error.

Can you clarify what you mean by that? How can two files be in the same file?

Do you mean that both files are in the same project? That both files are in the same directory on your disk? Something else?
MikeyBoy
They are in the same dirctory. Sry for my lateness.
Hi,

You might want to try creating a new standard console project with a different name (foo). If this first compiles, do these steps :
+ Create the header foo.h (if it doesn't exist)
+ Copy all content of abc.h to foo.h
+ In main.cpp, include foo.h and copy 'n' paste this line from abc.cpp :
1
2
3
4
void abc::something()
   {  a=5;
      std::cout<<"\n\t\t ...... IT WORKS ...... "<<a;
   }

... before the function main()
+ Apply your previous main() function
+ Replace every ("abc") you can find in your foo solution project with ("foo")
+ Compile the solution and let us know your program result.
Last edited on
They are in the same dirctory.
That doesn't necessarily mean that they are part of your project. Open the menu 'View' and activate 'Manager'. You will find a tab 'Projects' where all the files are listed which belongs to your project. Add the missing file...
closed account 5a8Ym39o6 and coder777 thank you for your suggestions.

As coder777 suggested I started a new a project and added main.cpp abc.cpp abc.h to it. No errors but blank console run screen.

As of closed account suggestion I simply added
1
2
3
4
void abc::something()
   {  a=5;
      std::cout<<"\n\t\t ...... IT WORKS ...... "<<a;
   }

to MAIN.cpp after the headers and that worked but still the same no error no output blank console.

I already tried to reset compiler setting but did not solve the issue.

EDIT: it seems non of my programs are producing outputs now.
Last edited on
Topic archived. No new replies allowed.