Jump to content
Sign in to follow this  
RSFalcon7

undefined reference to function

Recommended Posts

RSFalcon7

Bom dia,

normalmente resolvo este tipo de erros, mas quando faltam poucas horas para entregar um trabalho e o programa deixa de funcionar começo a dar em louco :wallbash:

O erro:

$ make main
g++ -g -c		-lpapi *.cpp 
g++ -g -o main  -lpapi *.o
main.o: In function `main':
.../main.cpp:40: undefined reference to `spmv<unsigned int, float>::spmv(unsigned int)'
.../main.cpp:52: undefined reference to `spmv<unsigned int, float>::spmv(unsigned int)'
collect2: ld returned 1 exit status
make: *** [main] Error 1

O main:

int main (int argc, char *argv[]) {

         ...

 unsigned int tmp = 2;
do{

	spmv<unsigned int, float> __spm2(tmp); //_spmv.init(tmp);
	cout << flush;

	tmp *= 2;
}while(tmp < 1024);

return 0;

o spmv.cpp:


#include <iostream>
#include <vector>

#include "spmv.h"


using namespace std;

template<typename iType,typename vType>
spmv<iType,vType>::spmv(unsigned int size)	{

	/*
	 *  Compressed Sparse Row matrix (aka CRS)
	 * /
	template <typename IndexType, typename ValueType>
	struct csr_matrix : public matrix_shape<IndexType>
	{
	    typedef IndexType index_type;
	    typedef ValueType value_type;

	    IndexType * Ap;  //row pointer
	    IndexType * Aj;  //column indices
	    ValueType * Ax;  //nonzeros
	}; */

csr = laplacian_5pt<iType,vType>(size); // Inicializa a matriz
// estatísticas sobre a matriz
cout	<< "Created Matrix " << csr.num_rows << " * " << csr.num_cols
		<< " = " << (long long)csr.num_rows * csr.num_cols
		<< " with " << csr.num_nonzeros << " non zeros (" 
		<< (double)(((csr.num_nonzeros)*100.0)/(csr.num_rows*csr.num_cols)) << " %)"
		<< endl
		<< "Witch is " << sizeof(csr)+csr.num_nonzeros*sizeof(vType)+csr.num_nonzeros*sizeof(iType)+(csr.num_rows+1)*sizeof(iType)
		<< " Kb" << endl;

srand(116);
ve = (vType *) malloc(csr.num_rows*sizeof(vType));

for(int i = 0 ; i < csr.num_rows ; i++)
	ve[i] = ((vType) rand());
}

template <typename iType,typename vType>
void spmv<iType,vType>::calc() {...}

O spmv.h:

// contém a função que inicializa a matriz
#include "io/gallery.h"

template <typename iType,typename vType> class spmv	{
private:
	vType *ve;
	csr_matrix<iType,vType> csr;
public:
	spmv(unsigned int);
	void calc ();
};

Não ligo se o spmv é uma classe ou deixa de ser, mas preciso dos templates para uso futuro, alguma luz sobre o erro?

Share this post


Link to post
Share on other sites
HappyHippyHippo

spmv<unsigned int, float> __spm2(tmp);

não será:

spmv<unsigned int, float> __spm2 = new spmv<unsigned int, float>(tmp);


IRC : sim, é algo que ainda existe >> #p@p

Share this post


Link to post
Share on other sites
RSFalcon7

Pelos vistos, tinha que colocar o código no .h, por ser um template é compilado em runtime

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.