Thread: Linking error....

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    14

    Linking error....

    Hi,

    I'm doing a project, I have a file called 'Building.h' a 'Building.cpp' where I define fonction of my classes, and a 'Main.cpp'

    In building.h I have:
    #ifndef Batiment_H
    #define Batiment_H
    class{.....};
    #endif


    In building.cpp I have:
    #include <iostream>
    #include "Building.h"

    in Main.cpp I have:
    #include <iostream>
    #include "Building.h"
    and my main simply call fonction in the Building.cpp like this:
    int main()
    {
    Building B;
    B.getpiece();
    B.setetage(0);
    B.getetage();
    return 0;

    }


    when I try to compile I have errors:

    Linking...
    main.obj : error LNK2001: unresolved external symbol "public: void __thiscall Building::getetage(void)" (?getetage@Batiment@@QAEXXZ)

    main.obj : error LNK2001: unresolved external symbol "public: void __thiscall Building::setetage(int)" (?setetage@Batiment@@QAEXH@Z)

    main.obj : error LNK2001: unresolved external symbol "public: void __thiscall Building::getpiece(void)" (?getpiece@Batiment@@QAEXXZ)

    main.obj : error LNK2001: unresolved external symbol "public: __thiscall Building::Building(void)" (??0Batiment@@QAE@XZ)

    Debug/main.exe : fatal error LNK1120: 4 unresolved externals

    Error executing link.exe.

    What I do wrong??? Is it really in error in linkiing files or I'm wrong???

    Thx for any help!
    Last edited by Mars_Volta; 06-03-2002 at 10:03 AM.

  2. #2
    Registered User
    Join Date
    Jun 2002
    Posts
    29
    You include building.h in your main, but I think you don't include building.cpp so functions defined there isn't available in main.cpp, you have only prototypes..

  3. #3
    Unregistered
    Guest
    Thanks man, stupid error, but damn in the book I'm studying they did not include the *.cpp in main.... is there another way??? or i'm just stuyding in a book full of mistake???

    thx mazo!

  4. #4
    Registered User
    Join Date
    Jun 2002
    Posts
    29
    Of course there is another way, it depends on your system, for example which compiler and IDE you are using.
    In Linux with gcc you can compile source in *.cpp to object *.o files and then compile main.cpp as 'gcc building.o main.cpp'..
    oh sorry you should g++ or what instead gcc..
    also there are some makefiles which are doing this automatically, but I don't know how to use them, I'm only a beginner
    In DOS IDEs you have projects and such things..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  3. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 04:49 AM
  4. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM