In function `main':: undefined reference to ...
Graf László
graf.laszlo@axis.hu
Tue Jan 18 08:40:00 GMT 2005
I did all what you said Sriharsha.
Whit file names changed, Makefile modified
I get the same message:
1. step: rm *.o
2. step: g++ -c base.cpp -o base.o
3. step: g++ axf.cpp base.o -o axf.o
/tmp/ccGshWGj.o(.text+0x4a): In function `main':
: undefined reference to `Base::Base[in-charge]()'
collect2: ld returned 1 exit status
Sriharsha wrote:
> Hi Laszlo,
> firstly, I suggest that you change the extension of your code files
> from .c to .cpp.
>
> then, in your make file: Change:
> g++ axf.c -o axf.o
> to
> g++ axf.cpp base.o -o axf.o
>
> Harsha.
>
> Graf LĂĄszlĂł wrote:
>
>> Hi Gurus,
>>
>> I am Laszlo from Hungary.
>> Please, take a look at these files:
>>
>> --- The main file
>> ---------------------------------------------------------------------
>> #include "stdio.h"
>> #include "stdlib.h"
>> #include "string.h"
>> #include "base.h"
>> int main(int argc, char* argv[])
>> {
>> system("clear");
>> Base* b = new Base();
>> printf("\n---------- %s ---------------\n", b->toString());
>> delete b;
>> return 0;
>> }//main
>>
>> --- The base.h file
>> ---------------------------------------------------------------------
>> #ifndef __BASE
>> #define __BASE
>> class Base{
>> private:
>> char* _str;
>>
>> public:
>> Base();
>> Base(Base &);
>> ~Base();
>>
>> char* toString();
>> char* toHtml();
>> };
>> #endif
>>
>> --- The base.c file
>> ---------------------------------------------------------------------
>> #include "base.h"
>> using namespace std;
>>
>> Base::Base(Base &s){
>> }
>>
>> Base::~Base(){
>> }
>>
>> char* Base::toString()
>> {
>> char* rv = "this is the toString()";
>> return rv;
>> }
>>
>> char* Base::toHtml()
>> {
>> char* rv = "this is the toHtml()";
>> return rv;
>> }
>>
>> --- The Makefile file
>> ---------------------------------------------------------------------
>> compile :
>> g++ -c base.c -o base.o
>> g++ axf.c -o axf.o
>> clear :
>> clear
>> clean :
>> rm *.o
>> run :
>> ./axf.o
>>
>> --------------------------------------------------------------------------------------------
>>
>> After the command
>> make clear clean compile run
>>
>> I got these error messages:
>>
>> rm *.o
>> g++ -c base.c -o base.o
>> g++ axf.c -o axf.o
>>
>> /tmp/cc2K7HjB.o(.text+0x4a): In function `main':
>> : undefined reference to `Base::Base[in-charge]()'
>>
>> /tmp/cc2K7HjB.o(.text+0x88): In function `main':
>> : undefined reference to `Base::toString()'
>> /tmp/cc2K7HjB.o(.text+0xaf): In function `main':
>> : undefined reference to `Base::~Base [in-charge]()'
>> collect2: ld returned 1 exit status
>>
>> make: *** [compile] Error 1
>>
>> Could somebody tell me what is wrong there?
>> Thank you.
>
>
>
--
Graf LĂĄszlĂł - bitfaragĂł
http://grafl.port5.com/
More information about the Gcc-help
mailing list