-
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!
-
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..
-
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!
-
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..