gcc
hi all.. I know I'll probably figure this out 2 mins after I post this but
this is driving me crazy.
After my hard drive went a few months ago, I've been slowly rebuilding my
debian system. I think I may not have installed gcc correctly. I am
trying to compile a very simple test program and I'm getting undefined reference errors.
Thanks!!!!
----------
myapp.cpp:
----------
#include <iostream.h>
#include "test1.h"
int main()
{
Test1 mytest1;
Test1 mytest2(30);
Test1 *pTest= new Test1;
cout << "mytest1.account = " << mytest1.GetAcct() << endl;
cout << "mytest2.account = " << mytest2.GetAcct() << endl;
cout << "pTest->account = " << pTest->GetAcct() << endl;
return 0;
}
--------
test1.h:
--------
#ifndef TEST1_H
#define TEST1_H
class Test1 {
public:
Test1();
Test1(int);
~Test1();
int GetAcct();
void SetAcct(int);
private:
int account;
};
#endif
----------
test1.cpp:
----------
#include "test1.h"
Test1::Test1(){
SetAcct(0);
}
Test1::Test1(int acct){
SetAcct(acct);
}
Test1::~Test1(){
;
}
int Test1::GetAcct(){
return account;
}
void Test1::SetAcct(int acct){
account = acct;
}
--------------------------
here's the error messages:
--------------------------
xucaen@whitestar:~/projects/test$ gcc myapp.cpp test1.o
/tmp/ccOTGokJ.o: In function `main':
/tmp/ccOTGokJ.o(.text+0x74): undefined reference to `endl(ostream &)'
/tmp/ccOTGokJ.o(.text+0x96): undefined reference to `cout'
/tmp/ccOTGokJ.o(.text+0x9b): undefined reference to `ostream::operator<<(char const *)'
/tmp/ccOTGokJ.o(.text+0xa6): undefined reference to `ostream::operator<<(int)'
/tmp/ccOTGokJ.o(.text+0xb1): undefined reference to `ostream::operator<<(ostream &(*)(ostream &))'
/tmp/ccOTGokJ.o(.text+0xbc): undefined reference to `endl(ostream &)'
/tmp/ccOTGokJ.o(.text+0xde): undefined reference to `cout'
/tmp/ccOTGokJ.o(.text+0xe3): undefined reference to `ostream::operator<<(char const *)'
/tmp/ccOTGokJ.o(.text+0xee): undefined reference to `ostream::operator<<(int)'
/tmp/ccOTGokJ.o(.text+0xf9): undefined reference to `ostream::operator<<(ostream &(*)(ostream &))'
/tmp/ccOTGokJ.o(.text+0x104): undefined reference to `endl(ostream &)'
/tmp/ccOTGokJ.o(.text+0x126): undefined reference to `cout'
/tmp/ccOTGokJ.o(.text+0x12b): undefined reference to `ostream::operator<<(char const *)'
/tmp/ccOTGokJ.o(.text+0x136): undefined reference to `ostream::operator<<(int)'
/tmp/ccOTGokJ.o(.text+0x141): undefined reference to `ostream::operator<<(ostream &(*)(ostream &))'
collect2: ld returned 1 exit status
Reply to:
- Follow-Ups:
- Re: gcc
- From: Peter Ross <peter.ross@miscrit.be>
- Re: gcc
- From: Peter Ross <peter.ross@miscrit.be>