undefined reference error when compiling

This is a discussion on undefined reference error when compiling within the C++ Programming forums, part of the General Programming Boards category; I am getting the above error on the lines marked here in the code. I have included my functions declarations ...

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    177

    undefined reference error when compiling

    I am getting the above error on the lines marked here in the code. I have included my functions declarations as well. Can someon please tell what is wrong and what can I do to remedy it?
    Code:
    StackCities(StartCity, EndCity, DistanceMatrix,
                      PredecessorMatrix, st, Reverse);//<--------HERE
    
          // Display the route - Start city to End city
          //==========================================================
          DispRoute(Reverse, st);     // For testing
    
          // Display the Intervening cities and the distances between
          // them including the cumulative distances for the route
          //==========================================================
          DispItinerary(st, StartCity, EndCity, DistanceMatrix, Reverse);//<-----HERE
    The function declarations:
    Code:
    void PrintPredChart(int cities, StringTable &st, TwoDIntArray &PredecessorArray);
    void DispItinerary(StringTable &st, string StartCity,  string EndCity, TwoDIntArray &DistanceMatrix, Stack &Reverse);
    void DispRoute(Stack &Reverse, StringTable &st);
    void InitMatrices(TwoDIntArray &DistanceMatrix, TwoDIntArray &PredecessorMatrix, int cities);
    void getMapData(ifstream &in, StringTable &st, char * buf, TwoDIntArray &DistanceMatrix, TwoDIntArray &PredecessorMatrix);
    void FloydWarshall(TwoDIntArray &DistanceMatrix, TwoDIntArray &PredecessorMatrix, int cities);
    void StackCities(string StartCity, string EndCity, TwoDIntArray &DistanceMatrix, TwoDIntArray &PredecessorMatrix, StringTable &st, Stack &Reverse);
    just in case:
    Code:
    int menuChoice;
        string StartCity;
        string EndCity;
        string fileName;
        //ifstream in;
    
        cout<<"Welcome to J.A.C. P2 Assignment\n"
          "\n"
          "This program will find the shortest path\n"
          "from One city to all other cities if there\n"
          "is a connecting node, find the shortest path\n"
          "between two cities or find the shortest\n"
          "between three or more cities.\n"<<endl;
    
        cout<<"Please make a choice of what you would like to do:\n"<<endl;
    
        cout<<"  1------> Shortest Path between 2 cities.\n"
              "  2------> Shortest Path between 3 or more cities.\n"
              "  3------> Shortest Path from 1 city to all.\n"
              "  9------> Take your ball and go home!\n"<<endl;
        cout<<"Waiting on you: "; cin>>menuChoice;
    
        switch (menuChoice) {
            case 1:
                cout<<"Enter the starting city: ";
                cin>>StartCity;
                cout<<"\nEnter the ending city: ";
                cin>> EndCity;
                cout<<"\nEnter the name of the file: ";
                cin>> fileName;
    
            break;
    Thank You.
    Code:
    obj\Debug\main.o||In function `main':|
    C:\Users\Documents\C++ Files\short\main.cpp|139|undefined reference to `StackCities(std::string, std::string, TwoDIntArray&, TwoDIntArray&, StringTable&, Stack&)'|
    C:\Users\Documents\C++ Files\short\main.cpp|148|undefined reference to `DispItinerary(StringTable&, std::string, std::string, TwoDIntArray&, Stack&)'|
    ||=== Build finished: 2 errors, 0 warnings ===|
    Last edited by csharp100; 05-07-2012 at 04:12 PM. Reason: added actual "build messages"

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    2,516
    FYI: You are NOT getting "undefined reference error" when compiling.
    These happen during the linking stage NOT the compiling stage.

    Do the linking correctly to fix the problem.
    Link to the needed object file/library.

    NOTE: If you want more help post the errors!

    Tim S.
    Last edited by stahta01; 05-07-2012 at 04:11 PM.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  3. #3
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,638
    It's also a good idea to paste the errors verbatim in your post.

  4. #4
    Registered User
    Join Date
    Jul 2010
    Posts
    177
    Quote Originally Posted by stahta01 View Post
    FYI: You are NOT get "undefined reference error when compiling".
    These happen during the linking stage NOT the compiling stage.

    Tim S.
    Hehe, nice drive-by, but thank you my mistake.

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    2,516
    Quote Originally Posted by csharp100 View Post
    Hehe, nice drive-by, but thank you my mistake.
    You are welcome.

    Tim S.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  6. #6
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,177
    Undefined references have nothing to do with declarations.

    Where are these functions defined? The object file compiled from that source is the file that will be needed which stahta01 (Tim) is talking about linking.

    Soma

  7. #7
    Registered User
    Join Date
    Jul 2010
    Posts
    177
    Quote Originally Posted by phantomotap View Post
    Undefined references have nothing to do with declarations.

    Where are these functions defined? The object file compiled from that source is the file that will be needed which stahta01 (Tim) is talking about linking.

    Soma
    Found it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error: undefined reference
    By 9erNumber16 in forum C++ Programming
    Replies: 1
    Last Post: 04-25-2012, 07:27 PM
  2. undefined reference error, please help me
    By leo2008 in forum C Programming
    Replies: 8
    Last Post: 03-27-2012, 03:50 AM
  3. Undefined Reference Error
    By NuNn in forum C Programming
    Replies: 12
    Last Post: 01-15-2009, 12:34 PM
  4. undefined reference error
    By gcctest in forum C Programming
    Replies: 3
    Last Post: 12-19-2008, 07:17 AM
  5. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM

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