Thread: Undefined reference problem

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    1

    Undefined reference problem

    Ok, when I compile I get this message:

    g++ -c main.cpp
    g++ -c bell.cpp
    g++ -c light.cpp
    g++ -c clock.cpp
    g++ -c person.cpp
    g++ -c elevator.cpp
    g++ -c building.cpp
    g++ -o outlab02 main.o bell.o light.o clock.o person.o building.o
    person.o: In function `Person::pressFloorButton(Building &)':
    person.o(.text+0x3e): undefined reference to `FloorButton::FloorButton(void)'
    person.o(.text+0x55): undefined reference to `FloorButton::pressButton(Building &, int)'
    collect2: ld returned 1 exit status
    make: *** [outlab02] Error 1

    I have no idea what's wrong. All the files appear to compile, and I've checked all the methods it asks for:

    In Person implementation:

    Code:
    /****pressFloorButton****/
    void Person::pressFloorButton(Building& build)
    {
      FloorButton button = FloorButton();
      button.pressButton(build, floor);
    }
    In FloorButton implementation:

    Code:
    /****buttonPressed()****/
    void FloorButton::pressButton(Building& build, int floor)
    {  build.buildingElevator.callElevator(floor);
    }
    In FloorButton definition:

    Code:
    /**
         * pressButton()                                             
         * Author: Jeff Balboni                                                                                                                                                                                            
         * Description: Signals for Elevator to come to floor                      
         **/
        void pressButton(Building& build, int floor);
    Help?

    (sorry about the width, I dunno what's with that)

  2. #2
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,090
    What is this line supposed to do?

    FloorButton button = FloorButton();

    If you are trying to create an instance of FloorButton using the default constructor, I would suggest this:

    FloorButton button;

    Don't know if that is your problem but it just looks suspicious.

  3. #3
    Master of the Universe! velius's Avatar
    Join Date
    Sep 2003
    Posts
    219
    An undefined reference to a function like those you're getting means you either did not write the functions or the source file is not compiled and cannot be found. Simply put the compiler CANNOT find those functions.
    While you're breakin' down my back n'
    I been rackin' out my brain
    It don't matter how we make it
    'Cause it always ends the same
    You can push it for more mileage
    But your flaps r' wearin' thin
    And I could sleep on it 'til mornin'
    But this nightmare never ends
    Don't forget to call my lawyers
    With ridiculous demands
    An you can take the pity so far
    But it's more than I can stand
    'Cause this couchtrip's gettin' older
    Tell me how long has it been
    'Cause 5 years is forever
    An you haven't grown up yet
    -- You Could Be Mine - Guns N' Roses

  4. #4
    Registered User
    Join Date
    May 2003
    Posts
    161
    g++ -o outlab02 main.o bell.o light.o clock.o person.o building.o
    elevator.o is not being linked.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. problem with the library
    By kris.c in forum C Programming
    Replies: 21
    Last Post: 07-10-2006, 08:29 PM
  3. Linking problem - undefined reference to load_parameters
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:28 AM
  4. How to: Use OpenGL with Jgrasp
    By Pickels in forum Game Programming
    Replies: 3
    Last Post: 08-30-2005, 10:37 AM
  5. Undefined Reference Problem
    By esilja in forum C++ Programming
    Replies: 1
    Last Post: 11-08-2001, 09:05 AM