0

below is my program. I want to link the implementation file to main function.


// implementation file
// imp.cpp
#include "myClass.hpp"
#include <iostream>

using namespace std;

int display(void)
{
cout<<"hello"<<endl;
}


// main function
//main.cpp
#include "myClass.hpp"

int main()
{
myClass sub;
sub.display();
return 0;
}

// header file.
//myClass.hpp
class myClass
{
public:
void display();
};


I compiled it using this syntax:
1.) g++ -c main.cpp
2.) g++ -c imp.cpp
3.) g++ main.o imp.o -o main.exe

the error displayed was:

In function `main':main.cpp:(.text+0x23): undefined reference to `myClass::display()'
collect2: ld returned 1 exit status

What this means? how could i remedy this problem?
please help me...

tnx in advance..

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

In your header file you declared display as a void function...in your imp.cpp file you called it an int function...it should be a void function...

0

Hmm... didn't read my advice in your previous thread regarding this issue?

The actual source files are fed to g++:

g++ main.cpp imp.cpp -o main.exe

[edit] and yeah, having the same return type helps...

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.