Thread: linker error (maybe to do with inheriting)

  1. #1
    Allways learning cs_student's Avatar
    Join Date
    Aug 2008
    Location
    ~/
    Posts
    39

    linker error (maybe to do with inheriting)

    I am getting the linker error
    Code:
    /var/tmp//ccyucL5u.o(.text+0x8d): In function `jp::SplashState::SplashState(std::string, int*, std::string)':
    : undefined reference to `jp::State::~State()'
    /var/tmp//ccyucL5u.o(.text+0x135): In function `jp::SplashState::SplashState(std::string, int*, std::string)':
    : undefined reference to `jp::State::~State()'
    /var/tmp//ccyucL5u.o(.text+0x1ae): In function `jp::SplashState::~SplashState()':
    : undefined reference to `jp::State::~State()'
    /var/tmp//ccyucL5u.o(.text+0x1ca): In function `jp::SplashState::~SplashState()':
    : undefined reference to `jp::State::~State()'
    /var/tmp//ccyucL5u.o(.text+0x24e): In function `jp::SplashState::~SplashState()':
    : undefined reference to `jp::State::~State()'
    /var/tmp//ccyucL5u.o(.text+0x26a): more undefined references to `jp::State::~State()' follow
    /var/tmp//ccyucL5u.o(.gnu.linkonce.r._ZTVN2jp11SplashStateE+0x28): undefined reference to `jp::SplashState::Pause()'
    /var/tmp//ccyucL5u.o(.gnu.linkonce.t._ZN2jp5StateC2ESsPi+0xf): In function `jp::State::State(std::string, int*)':
    : undefined reference to `vtable for jp::State'
    /var/tmp//ccyucL5u.o(.gnu.linkonce.r._ZTIN2jp11SplashStateE+0x8): undefined reference to `typeinfo for jp::State'
    I have four source files located at Index of /~poseidon/test

    I deleted all files that seemed not relevant and tpedefed my App class into an int so that I didn't have to include that either.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Giving us source files that you have modified so they differ from what exhibits your problem is pointless. That just forces people to guess. Like playing blind mans bluff.

    You presumably have the different classes in different source and header files. Make sure that all of the source files are compiled, and all of the corresponding object files are supplied to the linker.

    Just including a header file in the source for your main program is not enough.

    If you are using a project file, make sure all of the necessary source files are imported to the project (that will ensure all source files are compiled, and all object files are linked).

    If you are using a make file, make sure that it compiles all source files and then includes the corresponding object files on command line for linking.

    If you are entering command lines to compile or link, make sure that you compile all the necessary source files then specify all of the corresponding object files for the linker.
    Last edited by grumpy; 04-24-2011 at 03:07 AM.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    Allways learning cs_student's Avatar
    Join Date
    Aug 2008
    Location
    ~/
    Posts
    39
    I'm sorry, I did not word my sentence correctly. I deleted all files that were no relevant to the problem. I was able to delete all the other files and get the same error with just he files I supplied.
    I deleted them from the include, and their function calls. I tried to create a separate program as a test case.
    The problem I have occurs with just the files I linked to.
    I use this to compile.
    Code:
    g++ -Wall -o main main.cc splash_state.cc
    SOLVED. I had to implement the virtual dtor for the State class.
    Last edited by cs_student; 04-24-2011 at 06:53 PM.

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    There needs to be an implementation of the destructor for the State class included in the link. Using the same convention you are using for your other files, that function might be implemented in a state.cc. If you haven't such a file, you need to create it and implement the destructor in it.

    Declaring a destructor in a header file is not enough. If you declare it (which you have, in state.h), it is still necessary to implement it. Even if the class is abstract.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linker error
    By Panos83 in forum C Programming
    Replies: 6
    Last Post: 05-25-2008, 02:37 AM
  2. Linker Error
    By Bash in forum C++ Programming
    Replies: 13
    Last Post: 12-07-2007, 02:11 AM
  3. linker error
    By tasha302 in forum C++ Programming
    Replies: 3
    Last Post: 12-14-2006, 12:00 AM
  4. Linker Error
    By kris_619 in forum C Programming
    Replies: 3
    Last Post: 01-22-2005, 05:25 PM
  5. Linker Error !!!!
    By CodeJerk in forum C++ Programming
    Replies: 9
    Last Post: 11-15-2002, 07:34 AM