-
linker problem
i wrote a small prgrm using dev c++ but getting linker error, mentioned at the end..please help..code is quotated below..
Code:
#include <cstdlib>
#include <iostream>
#include "RealNumberProp.h"
int main(int argc, char *argv[])
{
RealNumberProp number;
number.getValue();
number.displayResult();
system("PAUSE");
return EXIT_SUCCESS;
}
#include <cstdlib>
#include <iostream>
#include <math.h>
class RealNumberProp
{
private:
double mRealNumber;
int upperBound(double);
int lowerbound(double);
bool isInteger(double);
public:
void getValue();
void displayResult();
};
#include <cstdlib>
#include <iostream>
#include "RealNumberProp.h"
int RealNumberProp::upperBound(double value)
{
return ceil(value);
}
int RealNumberProp::lowerbound(double value)
{
return floor(value);
}
bool RealNumberProp::isInteger(double value)
{
if((value==upperBound(value))&&(value==lowerBound(value)))
return true;
else
return false;
}
void RealNumberProp::getValue()
{
cout<<"Enter A Number";
cin>>mRealNumber;
}
void RealNumberProp::displayResult()
{
cout<<"The given number is a"<<isInteger(double mRealNumber)?cout<<"n Integer":cout<<" Non-Integar";
}
i get these linker errors:
have no idea why do the come up..
[Linker error] undefined reference to `RealNumberProp::getValue()'
[Linker error] undefined reference to `RealNumberProp::displayResult()'
-
What is your compiler command? It sounds like "RealNumberProp.cpp" [or whatever the last section of code is called] is not linked with the main file.
--
Mats
-
The compile log reads...
g++.exe "C:\Users\Shaleen\Documents\MyDevCppProjects\Dummy ProjMain.cpp" -o "C:\Users\Shaleen\Documents\MyDevCppProjects\Dummy ProjMain.exe" -ansi -traditional-cpp -g3 -I"C:\Users\Shaleen\MyProgramFiles\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Users\Shaleen\MyProgramFiles\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Users\Shaleen\MyProgramFiles\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Users\Shaleen\MyProgramFiles\Dev-Cpp\include\c++\3.4.2" -I"C:\Users\Shaleen\MyProgramFiles\Dev-Cpp\include" -L"C:\Users\Shaleen\MyProgramFiles\Dev-Cpp\lib" -g3
Three of my files : RealNumberProp.h, RealNumberProp.cpp and DummyProjMain.cpp are placed in "C:\Users\Shaleen\Documents\MyDevCppProjects\" directory.
Does this information helps in trblshooting?
-
And that proves what I said earlier - you are not compiling/linking your second .cpp file - my guess would be that it's not part of the project definition, so when you do "build", it doesn't know that you have two .cpp files that need to be build and linked.
You may also want to enable warnings in your compiler options [sorry, don't quite know how to do that, as I'm a command-line/makefile type of person when it comes to using gcc].
--
Mats
-
thanks matsp..it is wrking now..i created a nw project and included all of these files in it and compiled each of them separately and then rebuilt all..it didnt give any error...guess i wsn't using the project creation method properly..i just created three files in the same folder and thought that they would be linked by using #include...thanks for pointing out the fundamental problem...in my current log ..i can see that the second file is also built and linked..Thanks again