Undefined reference to function

So I have a really strange problem occurring...

First, here are the files I'm using:

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
//pa4.cpp wirtten by Syd Frederick
#include<iostream>
#include<string>
#include<fstream>
#include<sstream>
#include<cctype>
#include<cstdio>
#include "pa4functions.h"

int main(int argc, char* argv[])
{
	using std::cout;
	using std::cin;
	using std::endl;
	using std::string;
	using std::ifstream;

	synopsis();

	string in;

	if (argc <=1)
	{
		cout << "Missing Input File. Use " << argv[0] << " <Filename>" << endl;
		return(1);
	}

	else
	{
		ifstream iFile ( argv[1] );
		
		if ( !iFile.is_open() )
			cout << "Could not open file." << endl;
		else
		{
			cout << endl << "File: " << argv[1] << endl;
			char x;

			while ( iFile.get ( x ) )
			{
				cout << x;
				if (isalpha(x))
				{
					in+=x;
				}					
			}
		}
	iFile.close();
	}

	execute(in);
	return(0);
}	


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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
//Written by Syd Frederick
//Filename: pa4functions.cpp
//

#include<iostream>
#include<cctype>
#include<cstdio>
#include "letter_frequency.h"
#include "ltr_freq_pair.h"

using std::cout;
using std::cin;
using std::endl;
using std::string;

void synopsis()
{
	cout << "This program will take the file you have provided " << endl;
	cout << "and display a letter frequency of the contents. " << endl;
}

void execute(string in)
{
	string temp=in;

	for (int i=0; i<in.size(); i++)
	{
		in[i] = tolower(temp[i]);
	}

	letter_frequency letter_freq;
	
	ltr_freq_pair a_f;
	a_f.x='a';
	a_f.y=0;
	ltr_freq_pair b_f;
	b_f.x='b';
	b_f.y=0;
	ltr_freq_pair c_f;
	c_f.x='c';
	b_f.y=0;
	ltr_freq_pair d_f;
	d_f.x='d';
	d_f.y=0;
	ltr_freq_pair e_f;
	e_f.x='e';
	e_f.y=0;
	ltr_freq_pair f_f;
	f_f.x='f';
	f_f.y=0;
	ltr_freq_pair g_f;
	g_f.x='g';
	g_f.y=0;
	ltr_freq_pair h_f;
	h_f.x='h';
	h_f.y=0;
	ltr_freq_pair i_f;
	i_f.x='i';
	i_f.y=0;
	ltr_freq_pair j_f;
	j_f.x='j';
	j_f.y=0;
	ltr_freq_pair k_f;
	k_f.x='k';
	k_f.y=0;
	ltr_freq_pair l_f;
	l_f.x='l';
	l_f.y=0;
	ltr_freq_pair m_f;
	m_f.x='m';
	m_f.y=0;

	ltr_freq_pair n_f;
	n_f.x='n';
	n_f.y=0;
	ltr_freq_pair o_f;
	o_f.x='o';
	o_f.y=0;
	ltr_freq_pair p_f;
	p_f.x='p';
	p_f.y=0;
	ltr_freq_pair q_f;
	q_f.x='q';
	q_f.y=0;
	ltr_freq_pair r_f;
	r_f.x='r';
	r_f.y=0;
	ltr_freq_pair s_f;
	s_f.x='s';
	s_f.y=0;
	ltr_freq_pair t_f;
	t_f.x='t';
	t_f.y=0;
	ltr_freq_pair u_f;
	u_f.x='u';
	u_f.y=0;
	ltr_freq_pair v_f;
	v_f.x='v';
	v_f.y=0;
	ltr_freq_pair w_f;
	w_f.x='w';
	w_f.y=0;
	ltr_freq_pair x_f;
	x_f.x='x';
	x_f.y=0;
	ltr_freq_pair y_f;
	y_f.x='y';
	y_f.y=0;
	ltr_freq_pair z_f;
	z_f.x='z';
	z_f.y=0;

	for(int i=0; i<in.size(); i++)
	{
		if(in[i] == 'a')
		{
			a_f.y++;
		}
	}
	
	for(int i=0; i<in.size(); i++)
	{
		if(in[i] == 'b')
		{
			b_f.y++;
		}
	}
	
	for(int i=0; i<in.size(); i++)
	{
		if(in[i] == 'c')
		{
			c_f.y++;
		}
	}

	
	for(int i=0; i<in.size(); i++)
	{
		if(in[i] == 'd')
		{
			d_f.y++;
		}
	}

	
	for(int i=0; i<in.size(); i++)
	{
		if(in[i] == 'e')
		{
			e_f.y++;
		}
	}

	
	for(int i=0; i<in.size(); i++)
	{
		if(in[i] == 'f')
		{
			f_f.y++;
		}
	}

	
	for(int i=0; i<in.size(); i++)
	{
		if(in[i] == 'g')
		{
			g_f.y++;
		}
	}

	
	for(int i=0; i<in.size(); i++)
	{
		if(in[i] == 'h')
		{
			h_f.y++;
		}
	}

	
	for(int i=0; i<in.size(); i++)
	{
		if(in[i] == 'i')
		{
			i_f.y++;
		}
	}

	
	for(int i=0; i<in.size(); i++)
	{
		if(in[i] == 'j')
		{
			j_f.y++;
		}
	}

	
	for(int i=0; i<in.size(); i++)
	{
		if(in[i] == 'k')
		{
			k_f.y++;
		}
	}

	
	for(int i=0; i<in.size(); i++)
	{
		if(in[i] == 'l')
		{
			l_f.y++;
		}
	}

	
	for(int i=0; i<in.size(); i++)
	{
		if(in[i] == 'm')
		{
			m_f.y++;
		}
	}

	
	for(int i=0; i<in.size(); i++)
	{
		if(in[i] == 'n')
		{
			n_f.y++;
		}
	}

	
	for(int i=0; i<in.size(); i++)
	{
		if(in[i] == 'o')
		{
			o_f.y++;
		}
	}

	
	for(int i=0; i<in.size(); i++)
	{
		if(in[i] == 'p')
		{
			p_f.y++;
		}
	}

	
	for(int i=0; i<in.size(); i++)
	{
		if(in[i] == 'q')
		{
			q_f.y++;
		}
	}

	
	for(int i=0; i<in.size(); i++)
	{
		if(in[i] == 'r')
		{
			r_f.y++;
		}
	}

	
	for(int i=0; i<in.size(); i++)
	{
		if(in[i] == 's')
		{
			s_f.y++;
		}
	}

	
	for(int i=0; i<in.size(); i++)
	{
		if(in[i] == 't')
		{
			t_f.y++;
		}
	}

	
	for(int i=0; i<in.size(); i++)
	{
		if(in[i] == 'u')
		{
			u_f.y++;
		}
	}

	
	for(int i=0; i<in.size(); i++)
	{
		if(in[i] == 'v')
		{
			v_f.y++;
		}
	}

	
	for(int i=0; i<in.size(); i++)
	{
		if(in[i] == 'w')
		{
			w_f.y++;
		}
	}

	
	for(int i=0; i<in.size(); i++)
	{
		if(in[i] == 'x')
		{
			x_f.y++;
		}
	}

	
	for(int i=0; i<in.size(); i++)
	{
		if(in[i] == 'y')
		{
			y_f.y++;
		}
	}

	
	for(int i=0; i<in.size(); i++)
	{
		if(in[i] == 'z')
		{
			z_f.y++;
		}
	}

	letter_freq.push_back(a_f);
	letter_freq.push_back(b_f);
	letter_freq.push_back(c_f);
	letter_freq.push_back(d_f);
	letter_freq.push_back(e_f);
	letter_freq.push_back(f_f);
	letter_freq.push_back(g_f);
	letter_freq.push_back(h_f);
	letter_freq.push_back(i_f);
	letter_freq.push_back(j_f);
	letter_freq.push_back(k_f);
	letter_freq.push_back(l_f);
	letter_freq.push_back(m_f);
	letter_freq.push_back(n_f);
	letter_freq.push_back(o_f);
	letter_freq.push_back(p_f);
	letter_freq.push_back(q_f);
	letter_freq.push_back(r_f);
	letter_freq.push_back(s_f);
	letter_freq.push_back(t_f);
	letter_freq.push_back(u_f);
	letter_freq.push_back(v_f);
	letter_freq.push_back(w_f);
	letter_freq.push_back(x_f);
	letter_freq.push_back(y_f);
	letter_freq.push_back(z_f);

	cout << letter_freq << endl;
}
	


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//Written by Syd Frederick
//Filename: pa4functions.h
//
//void synopsis() displays a brief introduction and message to the user about the program
//
//void execute() takes a string created from the file and displays the frequencies
//
#include<string>

#ifndef PA4FUNCTIONS_H
#define PA4FUNCTIONS_H


void synopsis();
void execute(std::string in);

#endif 


When compiling I'm getting a strange error that says :
1
2
3
4
/tmp/ccdt0Bf9.o: In function `main':
pa4.cpp:(.text+0x1c): undefined reference to `synopsis()'
pa4.cpp:(.text+0x1e7): undefined reference to `execute(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
collect2: ld returned 1 exit status 


Seriously, I'm at a a loss. Any help would be greatly appreciated...
Add pa4functions.cpp file as compilation unit.
compile them using:
gcc -c pa4functions.cpp -o pa4functions.o
compile all of your .cpp files like this and link them with this command:
gcc your files.o -o pa4.exe -static-libgcc -static-libstdc++
Topic archived. No new replies allowed.