0

how could I link the implementation file to the header file and to the main function.

I made this program;

// This is my implementation file.. (imp.cpp)
#include <iostream>

using namespace std;

#include "CRectangle.hpp"

output()
{
cout<< "hello";
return 0;
}


// This is my header file..
#include <iostream>

using namespace std;

class CRectangle
{
public:
void output();
};


// This is my main function
#include <iostream>

using namespace std;

#include "CRectangle.hpp"

int main(void)
{
CRectangle A;
A.output();
}


:confused: The error is this:

/tmp/ccmKOGOR.o: In function `main':main.cpp:(.text+0x23): undefined reference to `CRectangle::output()'
collect2: ld returned 1 exit status


please help me... thanx in advance...

3
Contributors
2
Replies
3
Views
10 Years
Discussion Span
Last Post by John A
0

>To include your own header file, your need to build a project or makefile.
Most compilers don't require that header files are specified in makefiles/command arguments, since #include specifies where the file can be found.

More importantly, ensure that your source (.cpp) files are all added to your project/makefile, and the lack of them will cause the linker errors the OP was experiencing.

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.