In function `main':: undefined reference to ...
Sriharsha
sriharsha.v@redpinesignals.com
Tue Jan 18 08:14:00 GMT 2005
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.
--
*****************************
* Sriharsha Vedurmudi
* Software Engineer
*
* Redpine Signals Inc.
* Gate #395, Plot 87,88
* Sagar Society, Road #2,
* Banjara Hills,
* Hyderabad - 500 034
* www.redpinesignals.com
*
* +91-40-23559911 (Office)
* +91-98491-33133 (Mobile)
*****************************
More information about the Gcc-help
mailing list