Linking Errors: 1120 and 2019

Hi all,

I am trying to make a mathematics program for my own personal use and have searched the internet with no definitive answer to the common LNK2019 and LNK1120 errors. I would really appreciate if someone could show me what I have done wrong. I am using Microsoft Visual C++ 2010 Express Edition. The list of errors I get are:
1>------ Build started: Project: Mathematics Library, Configuration: Debug Win32 ------
1> Mathematics Functions.cpp
1>Mathematics Library.obj : error LNK2019: unresolved external symbol "int __cdecl greatestCommonDivisor<int>(class std::vector<int,class std::allocator<int> > &)" (??$greatestCommonDivisor@H@@YAHAAV?$vector@HV?$allocator@H@std@@@std@@@Z) referenced in function _main
1>C:\Users\Documents\Programming\Mathematics Library\Debug\Mathematics Library.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Thanks in advance.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
//Mathematics Functions.h file:

#ifndef MATHEMATICS_FUNCTIONS_H
#define MATHEMATICS_FUNCTIONS_H

#include <iostream>
#include <vector>

using namespace std;

template<typename Type>
Type greatestCommonDivisor(vector<Type> &);

#endif 


1
2
3
4
5
6
7
8
9
10
11
//Mathematics Functions.cpp file:

#include <vector>
#include "Mathematics Functions.h"

template<typename Type>
Type greatestCommonDivisor(vector<Type> &vec)
{
	cout << "hello world\n";
	return 1;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//Mathematics Library.cpp file:

#include <iostream>
#include <vector>
#include "Mathematics Functions.h"

using namespace std;

int main()
{
	vector<int> coordinates;

	coordinates.push_back(45);
	coordinates.push_back(12);
	coordinates.push_back(9);

	cout << greatestCommonDivisor(coordinates) << endl << endl;
//If I comment the line above, then the program compiles and runs perfect.
	system("pause");

	return 0;
}
Last edited on
Templates have to be entirely visible. You cannot hide the template implementation in a *.cpp.
Topic archived. No new replies allowed.