Menu

Undefined reference

Max
2007-06-26
2012-09-26
  • Max

    Max - 2007-06-26

    Sirs:

    I am studying C++ and I can not fix Dev C++ to work with this example from Deitel C++ book. I think will be very useful to run this book examples.

    I am using version 4.9.9.2

    Next errors messages:

    C:\Dev-Cpp\Ejemplos\Fig06_14.o(.text+0x149) In function main': [Linker error] undefined reference toTiempo::Tiempo(int, int, int)'

    C:\Dev-Cpp\Ejemplos\Fig06_14.o(.text+0x149) ld returned 1 exit status
    C:\Dev-Cpp\Ejemplos\Makefile.win [Build Error] ["Proyecto] Error 1

    Compilador: Default compiler
    Building Makefile: "C:\Dev-Cpp\Ejemplos\Makefile.win"
    Ejecutando make...
    make.exe -f "C:\Dev-Cpp\Ejemplos\Makefile.win" all
    g++.exe -DDEBUG Fig06_14.o -o "Proyecto 5.exe" -L"lib" -L"Ejemplos" -g3

    Fig06_14.o(.text+0x149): In function main': C:/Dev-Cpp/Ejemplos/Fig06_14.cpp:14: undefined reference toTiempo::Tiempo(int, int, int)'
    Fig06_14.o(.text+0x16c):C:/Dev-Cpp/Ejemplos/Fig06_14.cpp:15: undefined reference to Tiempo::Tiempo(int, int, int)' Fig06_14.o(.text+0x18f):C:/Dev-Cpp/Ejemplos/Fig06_14.cpp:16: undefined reference toTiempo::Tiempo(int, int, int)'
    Fig06_14.o(.text+0x1b2):C:/Dev-Cpp/Ejemplos/Fig06_14.cpp:17: undefined reference to `Tiempo::Tiempo(int, int, int)'

    Fig06_14.o(.text+0x1d5):C:/Dev-Cpp/Ejemplos/Fig06_14.cpp:18: undefined reference to Tiempo::Tiempo(int, int, int)' Fig06_14.o(.text+0x204):C:/Dev-Cpp/Ejemplos/Fig06_14.cpp:22: undefined reference toTiempo::imprimeUniversal()'
    Fig06_14.o(.text+0x223):C:/Dev-Cpp/Ejemplos/Fig06_14.cpp:24: undefined reference to Tiempo::imprimeEstandar()' Fig06_14.o(.text+0x242):C:/Dev-Cpp/Ejemplos/Fig06_14.cpp:27: undefined reference toTiempo::imprimeUniversal()'
    Fig06_14.o(.text+0x261):C:/Dev-Cpp/Ejemplos/Fig06_14.cpp:29: undefined reference to Tiempo::imprimeEstandar()' Fig06_14.o(.text+0x280):C:/Dev-Cpp/Ejemplos/Fig06_14.cpp:32: undefined reference toTiempo::imprimeUniversal()'
    Fig06_14.o(.text+0x29f):C:/Dev-Cpp/Ejemplos/Fig06_14.cpp:34: undefined reference to Tiempo::imprimeEstandar()' Fig06_14.o(.text+0x2be):C:/Dev-Cpp/Ejemplos/Fig06_14.cpp:37: undefined reference toTiempo::imprimeUniversal()'

    Fig06_14.o(.text+0x2dd):C:/Dev-Cpp/Ejemplos/Fig06_14.cpp:39: undefined reference to Tiempo::imprimeEstandar()' Fig06_14.o(.text+0x2fc):C:/Dev-Cpp/Ejemplos/Fig06_14.cpp:42: undefined reference toTiempo::imprimeUniversal()'
    Fig06_14.o(.text+0x31b):C:/Dev-Cpp/Ejemplos/Fig06_14.cpp:44: undefined reference to `Tiempo::imprimeEstandar()'
    collect2: ld returned 1 exit status

    make.exe: *** ["Proyecto] Error 1

    Ejecución Terminada


    Header file:

    // Fig. 6.12: tiempo2.h
    // Declaración de la clase Tiempo.
    // Las funciones miembro se definen en tiempo2.cpp

    // previene la inclusión múltiple del archivo de encabezado

    ifndef TIEMPO2_H

    define TIEMPO2_H

    // Definición del tipo de dato abstracto Tiempo
    class Tiempo {

    public:
    Tiempo( int = 0, int = 0, int = 0); // constructor predeterminado
    void estableceHora( int, int, int ); // establece hora, minuto, segundo
    void imprimeUniversal(); // imprime la hora en formato universal
    void imprimeEstandar(); // imprime la hora en formato estándar

    private:
    int hora; // 0 - 23 (formato de reloj de 24 horas)
    int minuto; // 0 - 59
    int segundo; // 0 - 59

    }; // fin de la clase Tiempo

    endif


    cpp file:

    // Fig. 6.14: fig06_14.cpp
    // Demostración de un constructor predeterminado para la clase Tiempo.

    include <iostream>

    using std::cout;
    using std::endl;

    // incluye la definición de la clase Tiempo desde tiempo2.h

    include "tiempo2.h"

    int main()
    {
    Tiempo t1; // todos los argumentos predeterminados
    Tiempo t2( 2 ); // minuto y segundo predeterminados
    Tiempo t3( 21, 34 ); // segundo predeterminado
    Tiempo t4( 12, 25, 42 ); // todos los valores especificados
    Tiempo t5( 27, 74, 99 ); // todos los valores no válidos especificados

    cout << "Construido con:\n\n"
    << "todos los argumentos predeterminados:\n ";
    t1.imprimeUniversal(); // 00:00:00
    cout << "\n ";
    t1.imprimeEstandar(); // 12:00:00 AM

    cout << "\n\nhora especificada; minuto y segundo predeterminados:\n ";
    t2.imprimeUniversal(); // 02:00:00
    cout << "\n ";
    t2.imprimeEstandar(); // 2:00:00 AM

    cout << "\n\nhora y minuto especificados; segundo predeterminado:\n ";
    t3.imprimeUniversal(); // 21:34:00
    cout << "\n ";
    t3.imprimeEstandar(); // 9:34:00 PM

    cout << "\n\nhora, minuto, y segundo especificados:\n ";
    t4.imprimeUniversal(); // 12:25:42
    cout << "\n ";
    t4.imprimeEstandar(); // 12:25:42 PM

    cout << "\n\ntodos valores no validos:\n ";
    t5.imprimeUniversal(); // 00:00:00
    cout << "\n ";
    t5.imprimeEstandar(); // 12:00:00 AM
    cout << endl;

    system("PAUSE");

    return 0;

    } // fin de main

    Thanks in advance

     
    • Max

      Max - 2007-06-27

      I include tiempo2.cpp to the project and run ok

      Thanks a lot!

       
    • Nobody/Anonymous

      >> // Las funciones miembro se definen en tiempo2.cpp

      Aparentemente no has incluido el fichero tiempo2.cpp en tu proyecto.

      ====== Translation:

      It seems that You forgot to include the tiempo2.cpp file in your's project.

      Old newbie

       
    • Anonymous

      Anonymous - 2007-06-27

      >> Next errors messages:

      No! Post the COMPLETE compile log (following a "rebuild all") so we can see exactly what you are compiling and linking. It seems likely that you are not linking the code that defines the Tiempo class. The associated .cpp file must be added to your project. Posting the complete log avoids having to make a guess.

      Clifford

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.