user defined header files

im trying to create my own libraries and header files and jst cant seem to get it right i try simple examples but compiler keep thorwing out same error heres my code;

try.h
1
2
3
4
5
6
7
8
#ifndef TRY_H_INCLUDED
#define TRY_H_INCLUDED


int SUM(int a , int b , int c);


#endif // TRY_H_INCLUDED 


try.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include "try.h"

using namespace std;

int SUM (int a , int b , int c )
{
    int sum;
    sum  = a + b + c;
    cout<< a <<" + "<< b <<" + "<< c <<" = "<<sum<<endl;
    return sum;

}


main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include "try.h"
using namespace std;

int main()
{
   int  x , y , z ;

   x = 5;
   y = 10 ;
   z = 15;

   int t = SUM( x, y, z );




return 0;

}


i dont know why but compiler keeps returning this error:
undefined reference to `SUM(int, int, int)

and im using code blocks as a compiler

plsssss any1 cn u plssss help me urgently
Are you linking the two cpp files?
uhm wat u mean?? hw do i do that ???
If you're using an IDE, make sure both of your cpp files are part of your project.

If you're not using an IDE, get an IDE.
im using code blocks and yes they both in the project bt still it returs da error
da


*wince*

The files in your project should be listed in the little explorer window on the left. Right click on each .cpp file, go to properties, and look around for a "compile this file" and "link this file" option. Make sure both are checked.

My guess is when you added the try.cpp file to the project you didn't check those options.
And be sure that the file belongs to the build target you are compiling
lol silly error guys soo this what you got to do....(for code blocks)

1) Go to the PROJECT , then right click and go to PROPERTIES...
2) han go to the BUILD TARGETS tab....
3) Look for the BUILD TARGET FILES at the bottom....
4) Now select all the .cpp and .h files and click ok
5) And boom it works lol
Topic archived. No new replies allowed.