cplusplus.com cplusplus.com
cplusplus.com   C++ : Forums : Beginners : newbie needs asstance with linker error
  Search:
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forums
Forums
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Articles
Lounge
Jobs

-

post  newbie needs asstance with linker error

shadowfire36 (9)
i got my code to finally compile but, now im getting 5 linker errors that i have no idea why im throwing them

the errors are:
1
2
3
4
5
football.obj : error LNK2019: unresolved external symbol "public: void __thiscall Football::SearchMatches(struct Match * * const,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,int)" (?SearchMatches@Football@@QAEXQAPAUMatch@@HV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z) referenced in function "public: void __thiscall Football::RunFootball(void)" (?RunFootball@Football@@QAEXXZ)
football.obj : error LNK2019: unresolved external symbol "public: void __thiscall Football::ReadLastSearchWord(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &,int &)" (?ReadLastSearchWord@Football@@QAEXAAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAH@Z) referenced in function "public: void __thiscall Football::RunFootball(void)" (?RunFootball@Football@@QAEXXZ)
football.obj : error LNK2019: unresolved external symbol "public: void __thiscall Football::SearchMatches(struct Match * * const,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?SearchMatches@Football@@QAEXQAPAUMatch@@HV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: void __thiscall Football::RunFootball(void)" (?RunFootball@Football@@QAEXXZ)
football.obj : error LNK2019: unresolved external symbol "public: void __thiscall Football::WriteLastSearchWord(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?WriteLastSearchWord@Football@@QAEXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: void __thiscall Football::RunFootball(void)" (?RunFootball@Football@@QAEXXZ)
D:\Documents and Settings\shadowfire36\Desktop\whochamp_do_not _edit\ed2\whos_the champ\Debug\whos_the champ.exe : fatal error LNK1120: 4 unresolved externals


here is new code and header

football.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef FOOTBALL_H
#define FOOTBALL_H


#include <iostream>
#include <fstream>
#include <string>
#include "Message.h"


using namespace std;

// definition of strct that will hold all information of match
struct Match
{
	string Season;
	string Team1;
	string Team2;
	string Result;
};



class Football : public Message  
{ 
public:

	void WriteLastSearchWord(string word);
	void ReadLastSearchWord(string &team, int &record);
	void SearchMatches(Match *matches[],int size,string TeamName);
	void SearchMatches(Match *matches[],int size,string TeamName, int record);
	void  RunFootball();
	Football(string *footBallData);


	
	


	
protected:	
	
	string &footBallSave;
	string team;
	
	


};

#endif  


football.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
 #include <iostream>
#include <fstream>
#include <string>
#include "Football.h"
#include "Message.h"


using namespace std;



//Search within array of matches and display the results
void SearchMatches(Match* matches,int size,string TeamName)
{
	//declare the result array
	Match SearchResult[2000];
	//initalize the result counter
	int SearchResultCount=0;

	int SelectedNumber;

	//search within the matches array
	for(int i=0;i<size;i++)
	{
		//check if the entered name is the team1 or team2 in the match
		if(matches[i].Team1==TeamName || matches[i].Team2==TeamName)
			{
				//update the search result counter
				SearchResultCount++;
				//display the seasons
				cout<<endl<<"("<<SearchResultCount<<") "<<matches[i].Season;
				//store the matched match in the search result array
				SearchResult[SearchResultCount] = matches[i];
			}
	}
	cout << endl;

	//check for results
	if(SearchResultCount>0)
	{
		cout << "which year would you like to view results "<<endl;
		cin>>SelectedNumber;

		SelectedNumber;
		
	ofstream myfile;
	myfile.open("nflSave.txt",ios::app);
	myfile << endl << SelectedNumber;
	myfile.close();
		
		//display the match information
		cout<<SearchResult[SelectedNumber].Season<<endl;
		cout<<SearchResult[SelectedNumber].Team1<<endl;
		cout<<"Over"<<endl;
		cout<<SearchResult[SelectedNumber].Team2<<endl;
		cout<<SearchResult[SelectedNumber].Result<<endl;
	}
	else cout<<"No search result";
	cout<<endl;
}
void SearchMatches(Match* matches,int size,string TeamName, int record)
{
	//declare the result array
	Match SearchResult;
	//initalize the result counter
	int SearchResultCount=0;

	//int SelectedNumber;

	//search within the matches array
	for(int i=0;i<size;i++)
	{
		//check if the entered name is the team1 or team2 in the match
		if(matches[i].Team1==TeamName || matches[i].Team2==TeamName)
			{
				//update the search result counter
				SearchResultCount++;
				if (SearchResultCount == record)
				{
					//store the 
				//display the seasons
				//cout<<endl<<"("<<SearchResultCount<<") "<<matches[i].Season;
				
			     //store the matched match in the search result array
				SearchResult = matches[i];
					break;
				}
			}
	}
	cout<<endl;

	//check for results
	if(SearchResultCount>0)
	{
		//display the match information
		cout<<SearchResult.Season<<endl;
		cout<<SearchResult.Team1<<endl;
		cout<<"Over"<<endl;
		cout<<SearchResult.Team2<<endl;
		cout<<SearchResult.Result<<endl;
	}
	else cout<<"No search result";
	cout<<endl;
}

// This function is used for storing the last search keyword entered to the recallteam.txt
void WriteLastSearchWord(string word)
{
	ofstream myfile;
    myfile.open("nflSave.txt");
    myfile << word;
    myfile.close();
}

// This function is used for read the last search keyword enter from the recallteam.txt
void ReadLastSearchWord(string &team, int &record)
{
	ifstream inFile("nflSave.txt");
	getline(inFile, team);
	inFile >> record;
	inFile.close();
}



void Football::RunFootball()
{	
	
	ifstream inFile("nfl.txt");
	//initailze the matches ( array of strcuts )
	Match *matches[2000];

	// create input stream for file
	

	//It will holds the read lines from the file
	string Buffer;

	// check if the file is exist 
	if(!inFile.is_open())
	{
		//display the error message
		//cout<<"Failed to open file"<<endl;
		cerr << " File is Missing";
	}

	// initalize the counter
	int matchesCounter=0;
	while(!inFile.eof())
	{                                        //&Match::operator =(const Match &)
		//read season
		matches[matchesCounter] = new Match;
		getline(inFile,Buffer);
		matches[matchesCounter]->Season = Buffer;
		//read team1 name
		getline(inFile,Buffer);
		matches[matchesCounter]->Team1  = Buffer;
		//read the "over" string
		getline(inFile,Buffer);
		//read team2 name
		getline(inFile,Buffer);
		matches[matchesCounter]->Team2 = Buffer;
		//read result
		getline(inFile,Buffer);
		matches[matchesCounter]->Result = Buffer;
		//read the empty line
		getline(inFile,Buffer);
		//update the matches counter
		matchesCounter++;
	}

	
	//its used for Main menu selection
	char Check='1';

	while(Check !='3')
	{
		//Display the main menu
	
		cin>>Check;
    
		switch(Check)
		{
			//Search 
		case '1':
			{
				string TeamName="";
				
				getline(cin,TeamName);
				system("cls");
				cout << "Please Enter Team City And Team Name" <<endl;
				getline(cin,TeamName);//free's buffer
				WriteLastSearchWord(TeamName);
				SearchMatches(matches,matchesCounter,TeamName);
				break;
			}
			//Display the last search team
		case '2':
			{
				string team;
				int record;
				ReadLastSearchWord(team, record);
				system("cls");
				cout << "Last Recorded Viewed" <<endl;
				SearchMatches(matches,matchesCounter ,team , record);
	           
				break;
			}
			//Exit the program
		case '3':
			{
				exit(0);
			}
		default:continue;
		
		}
	}
}
|
jsmith (158)
Given that every symbol you reference in football.cpp from main.cpp is undefined, I'd first suspect that you're not linking football.obj into the executable.

Can you post the linker command that is being executed to create the exe?
|
DiptenduDas (83)
U need to make below changes for the methods:

from

1
2
3
4
5
6
7
void SearchMatches(Match* matches,int size,string TeamName)
{
	//declare the result array
	Match SearchResult[2000];
......
......
}


to

from

1
2
3
4
5
6
7
void Football::SearchMatches(Match* matches,int size,string TeamName)
{
	//declare the result array
	Match SearchResult[2000];
......
......
}


Do same for other functions of class Football also.
| Last edited on

This topic is archived - New replies not allowed.
Home page | Privacy policy
© cplusplus.com, 2000-2008 - All rights reserved - v2.2
Spotted an error? contact us