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...

Member Avatar for GreenDay2001

To include your own header file, your need to build a project or makefile.

>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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.