Like Tree2Likes
  • 1 Post By manasij7479
  • 1 Post By King Mir

Classic "undefined reference" problem, headers... :s

This is a discussion on Classic "undefined reference" problem, headers... :s within the C++ Programming forums, part of the General Programming Boards category; Hey guys i've been getting this error lately... I think i should learns how to solve it once for all. ...

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    12

    Unhappy Classic "undefined reference" problem, headers... :s

    Hey guys i've been getting this error lately... I think i should learns how to solve it once for all.

    i declare a class "Libro" which stands for Book in english, anyway when i try to define the functions one get This error:
    undefined reference to `Libro::setAll(std::string, std::string, std::string, std::string, std::string)' but apparently to me i did it ok :P(crying in the inside)

    libro.h
    Code:
    #include<string>
    
    
    using namespace std;
    class Libro
    {    
            string titulo;
            string autor;
            string editora;
            string fechaPublicacion;
            string categoria;
            Libro *siguiente;
            //Libro *anterior;
    
    
        public:        
            void setAll(string,string,string,string,string);
            void setSiguiente(Libro *siguiente);
            Libro *getSiguiente();    
            string getCategoria();
            string getAutor();
            string getTitulo();        
    };
    libro.cpp
    Code:
    #include"libro.h"
    
    
    void Libro::setAll(string titulo,string autor,string editora,string fechapu,string categoria)
    {
        this->titulo = nombre;
        this->autor = autor;
        this->editora = editora;
        this->fechaPublicacion = fechapu;
        this->categoria = categoria;
    }
    
    
    void Libro::setSiguiente(Libro *libro)
    {
        this->siguiente = libro;
    }
    Libro* Libro::getSiguiente()
    {
        return this->siguiente;
    }
    string Libro::getCategoria()
    {
        return this->categoria;
    }
    string Libro::getAutor()
    {
        return this->autor;
    }
    string Libro::getTitulo()
    {
        return this->titulo;
    }
    Help please, any recomendations let me know im a notebook with blank pages

  2. #2
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    You probably forgot to provide the cpp file during compilation.
    adderly likes this.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  3. #3
    Registered User
    Join Date
    Oct 2011
    Posts
    12
    That did it! But surprinsigly i though i got this obviously i don't. Thanks!! By the way i can't i include the .h file instead,
    like those other libraries that all of us include?

    create header>create .cpp to define the header> include the .cpp?

    Thanks

  4. #4
    Registered User
    Join Date
    Apr 2006
    Posts
    2,032
    You do need to include the header, but that's not enough. You also need to sperately build each .cpp file into a .o file, before building the whole program. A good IDE, or something that can automatically generate make files will do this for you.
    adderly likes this.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  5. #5
    Registered User
    Join Date
    Oct 2011
    Posts
    12
    Ummmm.... that's right! the .o objects gets old(do not update) while my program grows. How Can i solve this? Im using Code::Blocks and even when i press rebuild or even clean, it is still referencing to and .o file not even relevant at the moment... :S

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,590
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can't Compile a code!!! I ran into "undefined reference to" error.
    By andereasmehdi in forum Linux Programming
    Replies: 19
    Last Post: 06-28-2011, 05:45 AM
  2. Problem with reading/writing in "classic" unix
    By StriderV in forum C Programming
    Replies: 13
    Last Post: 01-02-2011, 07:21 AM
  3. Replies: 4
    Last Post: 12-16-2008, 07:00 PM
  4. Replies: 5
    Last Post: 06-01-2006, 04:37 PM
  5. Replies: 11
    Last Post: 12-14-2005, 01:09 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21