unresolved external

This is a discussion on unresolved external within the C++ Programming forums, part of the General Programming Boards category; hi....i wrote this useless program for college assignment, it's relatively simple, when i finished it, it compiles fine, however i ...

  1. #1
    Registered User matheo917's Avatar
    Join Date
    Sep 2001
    Posts
    279

    unresolved external

    hi....i wrote this useless program for college assignment, it's relatively simple, when i finished it, it compiles fine, however i get this annoying linker error, that i have no clue how to approach and how to translate...it states this:

    Code:
    Deleting intermediate files and output files for project 'Assignment7 - Win32 Debug'.
    --------------------Configuration: Assignment7 - Win32 Debug--------------------
    Compiling...
    Assignment7.cpp
    Linking...
    Assignment7.obj : error LNK2001: unresolved external symbol "void __cdecl read_file(class std::basic_ifstream<char,struct std::char_traits<char> > &,class std::basic_ofstream<char,struct std::char_traits<char> > &,int &,int &)" (?read_file@@YAXAAV?$
    basic_ifstream@DU?$char_traits@D@std@@@std@@AAV?$basic_ofstream@DU?$char_traits@D@std@@@2@AAH2@Z)
    Assignment7.obj : error LNK2001: unresolved external symbol "void __cdecl total_length(class std::basic_ofstream<char,struct std::char_traits<char> > &,int &,int &)" (?total_length@@YAXAAV?$basic_ofstream@DU?$char_traits@D@std@@@std@@AAH1@Z)
    Debug/Assignment7.exe : fatal error LNK1120: 2 unresolved externals
    Error executing link.exe.
    
    Assignment7.exe - 3 error(s), 0 warning(s)
    can anyone help???


    Thanks...
    matheo917


    ... I would have attached the .cpp file but i can't seem to locate the option that let's me attach files in this forum...

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,659
    Are you preceding STL variables with std::? Or using namespace std::? Not sure though...STL errors are terrific, aren't they?



    ITSA
    Socket Library!

  3. #3
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    I'm not sure but I think it's either you have some problems in the functions' prototype.
    Maybe if you post some code it will be easier

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    You're trying to use functions that haven't been defined, the error will give you the name, so just find out where you're using the functions and why they aren't defined. It could be that you forgot a header file or a namespace qualification.

    -Prelude
    My best code is written with the delete key.

  5. #5
    Registered User matheo917's Avatar
    Join Date
    Sep 2001
    Posts
    279
    code is a bit long but if it helps you guy i'll post it, maybe you can look in whatever areas needed....

    Code:
    //---------------------------------------------------------------------------------------
    // Preprocessor directives...
    
    #include<iostream>
    #include<fstream>
    #include<cstring>
    #include<cstdlib>
    using namespace std;
    
    //---------------------------------------------------------------------------------------
    // Global constants...
    
    #define INPUT_FILE "input.txt"
    #define OUTPUT_FILE "output.txt"
    
    const int MAX = 66;
    
    //---------------------------------------------------------------------------------------
    // Functions declarations...
    
    void read_file(ifstream&, ofstream&, int&, int&);
    void calculate(ofstream&, int[], int, int[], int);
    void total_length(ofstream&, int&, int&);
    void compare_initial(ofstream&, int, int);
    void display(ofstream&, int, int, int, int, int, int, int, int, int, int, int, int, int, int);
    
    //---------------------------------------------------------------------------------------
    // driver function...
    
    int main()
    {
    	
    	ifstream fin(INPUT_FILE);				// object for file input
    	ofstream fout(OUTPUT_FILE);				// object for file output
    	
    	int first_length = 0;					// total length of the North/South road
    	int second_length = 0;					// total length of the West/East road
    	
    	if(fin.fail())
    	{
    		cout << "Can't open the file for input! Exiting! \n";
    		exit(0);
    	}
    
    	else
    	{
    		read_file(fin, fout, first_length, second_length);
    											// reads values from a text file...
    	}
    
    
    
    	fin.close();
    	fout.close();
    
    	return 0;
    
    }
    
    //---------------------------------------------------------------------------------------
    // read_file(): reads in values from a file into an array of integers
    //
    // Parameters:   ifstream object and ofstream object by reference
    // Return Value: void
    
    void read_file(ifstream& fin, ofstream& fout, int& first_length, int second_length)
    {
    
    	char first_road[MAX];
    	char second_road[MAX];
    	
    	int current_first = 0;				// stands for initial level point of N/S road
    	int current_second = 0;				// stands for initial level point of W/E road
    	
    	int first_level[MAX];				// an array of 66 integer values...
    	int second_level[MAX];				// 
    
    	int first_max = 1;					// stand for indexes of arrays of integers...
    	int second_max = 1;
    
    	fin.getline(first_road, MAX);		// reads in characters till the 'eol' symbol...
    
    	for(int i = 0; ((first_level[i] != -999) || (i < MAX)); i++)
    	{
    		fin >> first_level[i];
    		
    		if(first_level[i] != -999)
    		{
    	
    			current_first = (current_first + first_level[i]);
    
    			first_max++;						// implementing counter for index of an array
    
    			first_length = (first_length + 100);	// adds 100 feet to total length of
    		}											// the first road...
    
    	}
    
    
    	fin.getline(second_road, MAX);		// reads in characters till 'eol' symbol...
    
    	for(int j = 0; ((second_level[j] != -999) || (j < MAX)); j++)
    	{
    		fin >> second_level[j];
    
    		if(second_level[j] != -999)
    		{
    			current_second = (current_second + second_level[j]);
    
    			second_max++;						// incrementing counter for index of an array
    
    			second_length = (second_length + 100);	// adds 100 feet to total length of
    		}											// of the second road...
    
    	}
    
    
    	total_length(fout, first_length, second_length);
    	
    	calculate(fout, first_level, first_max, second_level, second_max);
    	
    	compare_initial(fout, first_level[0], second_level[0]);
    
    }
    
    
    //---------------------------------------------------------------------------------------
    // calculate(): will do various computations on the arrays such as: the largest and
    //				the smallest value; total number of highs and lows versus the initial
    //				elevation of the roads
    //
    // Parameters:   ofstream object by reference, array of integers, integer, array of 
    //				 integers, and an integer
    // Return Value: void
    
    void calculate(ofstream& fout, int first_level[], int first_max, int second_level[],
    			   int second_max)
    {
    	int marker_first_highest, marker_first_lowest;
    	int marker_second_highest, marker_second_lowest;
    	
    	int first_starter = first_level[0];
    	int second_starter = second_level[0];
    	
    	int first_highest = first_level[0],
    		second_highest = second_level[0],
    		first_lowest = first_level[0],
    		second_lowest = second_level[0],
    		total_first_higher = 0,
    		total_second_higher = 0,
    		total_first_lower = 0,
    		total_second_lower = 0, 
    		total_first_equal = 0,
    		total_second_equal = 0;
    
    		
    	for (int i = 0; i < first_max; i++)				// traversing the first array...
    	{
    	
    		if(first_level[i] > first_highest)
    		{
    			first_highest = first_level[i];
    			marker_first_highest = i;
    		}
    
    		if(first_level[i] < first_lowest)
    		{
    			first_lowest = first_level[i];
    			marker_first_lowest = i;
    		}
    
    
    		if(first_level[i] > first_starter)
    		{
    			total_first_higher++;				// incrementing a total of numbers larger than
    												// the starting level point...
    		}
    
    		else if(first_level[i] < first_starter)
    		{
    			total_first_lower++;
    		}
    
    		else if(first_level[i] == first_starter)
    		{
    			total_first_equal++;
    		}
    
    	}
    
    
    
    	for (int j = 0; j < second_max; j++)				// traversing the second array...
    	{
    	
    		if(second_level[j] > second_highest)
    		{
    			second_highest = second_level[j];
    			marker_second_highest = j;
    		}
    
    		if(second_level[j] < second_lowest)
    		{
    			second_lowest = second_level[j];
    			marker_second_lowest = j;
    		}
    
    
    		if(second_level[j] > second_starter)
    		{
    			total_second_higher++;				// incrementing a total of numbers larger than
    												// the starting level point...
    		}
    
    		else if(second_level[j] < second_starter)
    		{
    			total_second_lower++;
    		}
    
    		else if(second_level[j] == second_starter)
    		{
    			total_second_equal++;
    		}
    
    	}
    
    
    	display(fout,
    			marker_first_highest,			// calling a function that will display
    			marker_first_lowest,			// all the necessary data required by
    			marker_second_highest,			// by an engineer...
    			marker_second_lowest,
    			first_highest,
    		    second_highest,
    			first_lowest,
    			second_lowest,
    			total_first_higher,
    			total_second_higher,
    			total_first_lower,
    			total_second_lower, 
    			total_first_equal,
    			total_second_equal);
    
    }
    
    
    //---------------------------------------------------------------------------------------
    // display(): write the results from the calculate() function into a file
    //
    // Parameters:   ofstream object, 14 integers, avoid logical errors
    // Return Value: void
    
    void display(ofstream& fout,
    			 int marker_first_highest,
    			 int marker_first_lowest,
    			 int marker_second_highest,
    			 int marker_second_lowest,
    			 int first_highest,
    		     int second_highest,
    			 int first_lowest,
    			 int second_lowest,
    			 int total_first_higher,
    			 int total_second_higher,
    			 int total_first_lower,
    			 int total_second_lower, 
    			 int total_first_equal,
    			 int total_second_equal)
    {
    	
    	fout << "The highest point of the road from North to South is: " << first_highest << endl
    		 << "That point's index marker is: "<< marker_first_highest << endl
    		 << "The lowest point of the road from North to South is: " << first_lowest << endl
    		 << "That point's index marker is: " << marker_first_lowest << "\n\n";
    
    	fout << "Total number of levels higher than the initial level of N/S road is: "
    		 << total_first_higher << endl
    		 << "Total number of levels lower than the initial level of N/S road is: "
    		 << total_first_lower << endl
    		 << "Total number of levels equal to the initial level of N/S road is: "
    		 << total_first_equal << "\n\n";
    
    	fout << "The highest point of the road from West to East is: " << second_highest << endl
    		 << "That point's index marker is: " << marker_second_highest << endl
    		 << "The lowest point of the road from West to East is: " << second_lowest << endl
    		 << "That point's index marker is: " << marker_second_lowest << "\n\n";
    
    	fout << "Total number of levels higher than the initial level of W/E road is: "
    		 << total_second_higher << endl
    		 << "Total number of levels lower than the initial level of W/E road is: "
    		 << total_second_lower << endl
    		 << "Total number of levels equal to the initial level of W/E road is: "
    		 << total_second_equal << "\n\n\n";
    }
    
    
    //---------------------------------------------------------------------------------------
    // total_length(): writes the total length of each road into a file
    //
    // Parameters:   ofstream object by reference, 2 integers
    // Return Value: void
    
    void total_length(ofstream& fout, int first_length, int second_length)
    {
    	fout << "The total length of the road going from North to South is \n"
    		 << first_length << " feet long. \n\n";
    
    	fout << "The total length of the road going from West to East is \n"
    		 << second_length << " feet long. \n\n";
    }
    
    
    //---------------------------------------------------------------------------------------
    // compare_initial(): compares initial values of the two roads and gives the highest
    // 
    // Parameters:   ofstream object by reference, 2 initial integers...
    // Return Value: void
    
    void compare_initial(ofstream& fout, int first, int second)
    {
    	int difference = 0;				// difference between initial elevations
    	
    	if(first > second)
    	{
    		difference = (first - second);
    		fout << "The road going from North to South has a higher starting \n"
    			 << "point level, by " << difference << " units. \n\n";
    	}
    
    	else if(second > first)
    	{
    		difference = (second - first);
    		fout << "The road going from West to East has the higher starting \n"
    			 << "point level, by " << difference << " units. \n\n";
    	}
    
    	else
    	{
    		fout << "The starting point levels of both roads are equal. \n\n";
    	}
    
    }
    
    //---------------------------------------------------------------------------------------


    THANKS

  6. #6
    Registered User matheo917's Avatar
    Join Date
    Sep 2001
    Posts
    279
    PRELUDE --------------- what do you mean by "the functions that haven't been defined" ???

    if you look at my code, it seems like all user defined functions declrarations match the functions headers in their definitions below????

    thanks.....

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >it seems like all user defined functions declrarations match the functions headers in their definitions below????

    Declaration:
    >void read_file(ifstream&, ofstream&, int&, int&);
    Definition (names omitted):
    >void read_file(ifstream&, ofstream&, int&, int)

    Declaration:
    >void total_length(ofstream&, int&, int&);
    Definition (names omitted):
    >void total_length(ofstream&, int, int)

    This sure looks like the declared functions aren't defined to me. If the definition doesn't match the prototype then you'll get a linker error.

    -Prelude
    My best code is written with the delete key.

  8. #8
    Registered User matheo917's Avatar
    Join Date
    Sep 2001
    Posts
    279
    you're right, i guess sometimes i can't even spot such simple errors, maybe b/c it was too late at night and my eyes were tired

    thanx anyway....

    hmmm...compiles and links...but it crashes...hmmm now back to the basics...

  9. #9
    Registered User matheo917's Avatar
    Join Date
    Sep 2001
    Posts
    279
    fixed everything...all is up and running correctly....

    Thanks to all....

    especially Prelude for a very informative lesson.....

    later....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 02:07 AM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 01:28 PM
  4. debug to release modes
    By DavidP in forum Game Programming
    Replies: 5
    Last Post: 03-20-2003, 02:01 PM
  5. Unresolved external symbols in OGL
    By Shadow12345 in forum Game Programming
    Replies: 4
    Last Post: 08-04-2002, 09:46 PM

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