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)

// main function
#include "myClass.hpp"

int main()
myClass sub;
return 0;

// header file.
class myClass
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..

Recommended Answers

All 2 Replies

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

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

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.