
17th March 2009, 03:10 PM
|
|
Registered User
|
|
Join Date: Aug 2008
Posts: 16

|
|
|
undefined reference when link with g++
I write two files:
Quote:
//SelectSort.cpp
#include<iostream>
using namespace std;
template <class T>
void SelectionSort(T p[],int n)
{
}
|
Quote:
//main.cpp
#include<iostream>
#include<iomanip>
using namespace std;
template <class T>
void SelectionSort(T p[],int n);
int main()
{
int p[8]={1,7,3,6,2,8,3,4};
SelectionSort<int>(p,8);
return 0;
}
|
then i compile the sorce file with
Quote:
g++ -c SelectSort.cpp -o SelectSort.o
g++ -c main.cpp -o main.o
g++ -o main main.o SelectSort.o
|
the error when linking is :
Quote:
main.o: In function `main':
main.cpp .text+0x9c): undefined reference to `void SelectionSort<int>(int*, int)'
collect2: ld returned 1 exit status
|
|