By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,853 Members | 2,246 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,853 IT Pros & Developers. It's quick & easy.

g++ compiling

P: 22
I can't compile this using g++
michael@michael:~/g++$ g++ program.cpp
//ClassA.h
class ClassA{
private:
int atribute;
public:
ClassA(int atribute);
};
//ClassA.cpp
#include "ClassA.h"

ClassA::ClassA(int atribute){
this->atribute = atribute;
}
//program.cpp
#include "ClassA.h"
#include <iostream>

int main(){
ClassA object(10);
return 1;
}

the compiler returns the folowing error msg:

/tmp/ccwwAJmP.o(.text+0x1f): In function `main':
: undefined reference to `ClassA::ClassA[in-charge](int)'
collect2: ld returned 1 exit status
Sep 20 '06 #1
Share this Question
Share on Google+
2 Replies


100+
P: 144
You need to provide the compiler with all the necessary source files. You neglected to tell it that ClassA.cpp contains code needed to properly link the program. The following should solve your problem.

g++ program.cpp ClassA.cpp
Sep 20 '06 #2

P: 22
thank you very much!
Sep 21 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.