Problems with constructors

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • saneman

    #1

    Problems with constructors

    I am trying to compile the program from this page:



    I use this makefile:

    all: main

    main: helloworld.h helloworld.cc main.cc
    g++ main.cc -o main `pkg-config gtkmm-2.4 --cflags --libs`

    But when I compile I get:

    /tmp/ccPWqvDE.o: In function `main':
    main.cc:(.text+ 0x37): undefined reference to `HelloWorld::He lloWorld()'
    main.cc:(.text+ 0x54): undefined reference to `HelloWorld::~H elloWorld()'
    main.cc:(.text+ 0x67): undefined reference to `HelloWorld::~H elloWorld()'
    collect2: ld returned 1 exit status
    make: *** [main] Error 1

    But I don't understand why since the constructors are specified.
  • Martin York

    #2
    Re: Problems with constructors

    On Mar 30, 9:31 am, saneman <d...@sdf.comwr ote:
    I am trying to compile the program from this page:
    >
    http://www.gtkmm.org/docs/gtkmm-2.4/...sec-helloworld...
    >
    I use this makefile:
    >
    all: main
    >
    main: helloworld.h helloworld.cc main.cc
    g++ main.cc -o main `pkg-config gtkmm-2.4 --cflags --libs`
    >
    But when I compile I get:
    >
    /tmp/ccPWqvDE.o: In function `main':
    main.cc:(.text+ 0x37): undefined reference to `HelloWorld::He lloWorld()'
    main.cc:(.text+ 0x54): undefined reference to `HelloWorld::~H elloWorld()'
    main.cc:(.text+ 0x67): undefined reference to `HelloWorld::~H elloWorld()'
    collect2: ld returned 1 exit status
    make: *** [main] Error 1
    >
    But I don't understand why since the constructors are specified.
    This is not a problem with your code but a problem with what you are
    building.
    Your code is in two files main.cc and helloworld.cc but you are only
    building main.cpp

    You should probably drop a note to a group that can help you get your
    makefile set up correctly. As a temporary solution change the build
    line to:



    g++ main.cc helloworld.cc -o main `pkg-config gtkmm-2.4 --
    cflags --libs`

    Notice: ^^^^^^^^^^^^

    Comment

    • saneman

      #3
      Re: Problems with constructors

      Alf P. Steinbach wrote:
      * saneman:
      >I am trying to compile the program from this page:
      >>
      >http://www.gtkmm.org/docs/gtkmm-2.4/...elloworld.html
      >>
      >>
      >I use this makefile:
      >>
      >all: main
      >>
      >main: helloworld.h helloworld.cc main.cc
      > g++ main.cc -o main `pkg-config gtkmm-2.4 --cflags --libs`
      >>
      >But when I compile I get:
      >>
      >/tmp/ccPWqvDE.o: In function `main':
      >main.cc:(.text +0x37): undefined reference to `HelloWorld::He lloWorld()'
      >main.cc:(.text +0x54): undefined reference to `HelloWorld::~H elloWorld()'
      >main.cc:(.text +0x67): undefined reference to `HelloWorld::~H elloWorld()'
      >collect2: ld returned 1 exit status
      >make: *** [main] Error 1
      >>
      >But I don't understand why since the constructors are specified.
      >
      You have forgotten 'helloworld.cc' in the compilation command.
      >
      >
      Cheers, & hth.,
      >
      - Alf
      >
      Ah is there someway to split this up in to targets or is this offtopic?

      Comment

      Working...