Unresolved external error

This is a discussion on Unresolved external error within the C++ Programming forums, part of the General Programming Boards category; Hi all, I'm trying to complete a C++ assign. Im in a mad rush as I have to hand in ...

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

    Exclamation Unresolved external error

    Hi all,

    I'm trying to complete a C++ assign. Im in a mad rush as I have to hand in the assign. tommorrow . On compiling I am getting an unresolved external error in relation to a user library that I am trying to use. Code as follows:


    Assig1:
    Code:
    Marks[MAX_NO_MARKS];
    int HiMark, LoMark, TotalNoMarks;
    
    if(MarksFile)
    {
    TotalNoMarks = ReadMarks (MarksFile, Marks);
    SortArray (TotalNoMarks, Marks);
    FindHiLo (Marks, TotalNoMarks, HiMark, LoMark);
    DisplayMarks (Marks, TotalNoMarks, HiMark, LoMark);
    MarksFile.close();
    }
    
    else
    {
    cout<<"File does not exist";
    getch();
    }
    
    }
    //*****************************************************************
    int ReadMarks (ifstream &MarksFile, int Marks[])
    {
    int Count = 0;
    
    while (!MarksFile.eof() && Count < MAX_NO_MARKS)
    {
    MarksFile>>Marks[Count];
    Count++;
    }
    
    return Count;
    }
    //*****************************************************************
    void FindHiLo (int Marks[], int TotalNoMarks, int &HiMark, int &LoMark)
    {
    int Count = 0;
    
    HiMark = 0;
    LoMark = 0;
    
    for (Count = 0; Count < TotalNoMarks; Count++)
    {
    if (Marks[Count] >= IGNORE_LO && Marks[Count] <= IGNORE_HI)
    {
    if (Marks[Count] < LoMark)
    {
    LoMark = Marks[Count];
    }
    
    if (Marks[Count] > HiMark)
    {
    HiMark = Marks[Count];
    }
    
    Count++;
    }
    
    
    }
    
    }
    //*****************************************************************
    void DisplayMarks (int Marks[], int TotalNoMarks, int HiMark, int LoMark)
    {
    int Count, tempCount, tempMark, tabstop;
    
    tabstop = 10;
    
    clrscr();
    
    cout<<"Highest"<<setw(tabstop)<<HiMark<<endl;
    cout<<"Lowest"<<setw(tabstop)<<LoMark<<endl<<endl;
    
    cout<<endl;
    
    tempMark=Marks[0];
    
    cout<<tempMark<<setw(10)<<"*";
    
    for (Count = 1; Count < TotalNoMarks; Count++)
    {
    tempMark = Marks[Count];
    
    if (tempMark == Marks[Count-1])
    {
    cout<<"*";
    }
    else
    cout<<endl<<tempMark<<setw(tabstop)<<"*";
    
    }
    
    cout<<"\n\n\n";
    getch();
    }
    Code:
    intsort.h:
    void SortArray ( int NumberElements, int Array[] );
    intsort.cpp:
    Code:
    void SortArray ( int NumberElements, int Array[] )
    {
    int outer, inner;
    int tempint;
    
    for ( outer = NumberElements - 1; outer>0; outer-- )
    {
    for ( inner = 0; inner < outer; inner++ )
    {
    if (Array[inner] > Array[inner+1] )
    {
    tempint = Array[inner];
    Array[inner] = Array[inner+1];
    Array[inner+1] = tempint;
    }
    }
    }
    }
    Again thanx very much for your help

    Kirk

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,546
    > compiling I am getting an unresolved external error in relation to a user library that I am trying to use
    Which operating system?
    Which compiler?
    What library?
    What error messages?

    What have you tried so far, by way of telling your linker where the user library is (there's more to it that simply #include - that's only for the compiler).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    3
    Sorry - I'm new to C++. Im using Bcc32 (the free Borland compiler) under windows XP SP2. The library is intsort.h (user library) which I have placed in the same directory as the .cpp files included in my first post. The exact error reads:

    Code:
    Error: Unresolved external 'SortArray(int, int *)' referenced from C:\C++ CODE\ASSIG1.OBJ
    >Exit code: 1

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    It looks like the first few lines of your program were cut off/forgotten. I suspect they look(ed) something like this:

    Code:
    //list of includes should be at top of driver file
    #include <iostream>
    #include "SortArray.h"
     
    //deal with namespace requirements for up to date version of iostream
    using namespace std;
     
    //declare functions defined after main
    int ReadMarks (ifstream &, int []);
    void FindHiLo (int [], int, int &, int &);
    void DisplayMarks (int [], int, int, int);
     
    //declare main
    int main()
    {
    I suspect you didn't include SortArray.h in the list of includes. Hence, the linker can't find any information about SortArray() and sends the error you have listed.
    On a side note: if the board didn't screw up your indentation, you should really establish a personal indentation style to make your code more readable.
    You're only born perfect.

  5. #5
    Registered User
    Join Date
    Aug 2005
    Posts
    3
    Yeah sorry I didn't notice that I cut off the top it reads:

    Code:
    //****************************************************************
    //Libraries
    
    #include <fstream.h>
    #include <conio.h>
    #include <iomanip.h>
    #include "intsort.h"
    
    //****************************************************************
    //Prototypes
    
    int ReadMarks (ifstream &MarksFile, int Marks[]);
    void FindHiLo (int Marks[], int TotalNoMarks, int &HiMark, int &LoMark);
    void DisplayMarks (int Marks[], int TotalNoMarks, int HiMark, int LoMark);
    
    void SortArray ( int NumberElements, int Array[] );      //Remove once linking issue resolved
    
    //****************************************************************
    //Constants
    
    const int MAX_NO_MARKS = 50;
    const int IGNORE_HI = 100;
    const int IGNORE_LO = 0;
    //****************************************************************
    void main()
    {
        ifstream MarksFile ("highmark.dat");
        int Marks[MAX_NO_MARKS];
        int HiMark, LoMark, TotalNoMarks;
        
        if(MarksFile)
        {
            TotalNoMarks = ReadMarks (MarksFile, Marks);
            SortArray (TotalNoMarks, Marks);
            FindHiLo (Marks, TotalNoMarks, HiMark, LoMark);
            DisplayMarks (Marks, TotalNoMarks, HiMark, LoMark);
            MarksFile.close();        
        }
        
        else
        {
            cout<<"File does not exist";
            getch();        
        }
        
    }

  6. #6
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    You have a created a perfect example of why namespaces can be useful. In particular you have a name clash with the function SortArray() becuase you have declared and defined a function called SortArray in intSort.h and intSort.cpp in addition to a function called SortArray outside of intSort.h but both are in your program. Therefore, the linker isn't sure which version of SortArray to use so it is calling it an unresolved external error. I suspect if you comment out the prototype for SortArray you have typed just above the declaration of the global constants, that this error will resolve.

    BTW, your indentation is much better with this last post, congrats. However, it should be int main() not void main() and, if your compiler supports it, you should really consider using the updated versions of iostream, etc. and handle the namespace issue associated therewith in a manner you are comfortable with.
    You're only born perfect.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 03:35 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  4. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM
  5. Help with error
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 04-17-2002, 09:36 AM

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