Thread: linker problem

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    3

    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()'

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Aug 2008
    Posts
    3
    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?

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Aug 2008
    Posts
    3
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mysterious Linker Error
    By Night_Blade in forum Windows Programming
    Replies: 0
    Last Post: 04-30-2006, 01:50 PM
  2. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  3. vc++ linker options problem
    By fnoyan in forum C++ Programming
    Replies: 2
    Last Post: 12-08-2005, 11:22 AM
  4. Replies: 5
    Last Post: 11-07-2005, 11:34 PM
  5. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM