cudaGetTextureReference sample code fails

Im developing a lib for some opengl interop stuffs. Currently i get stuck on this texture reference problem.

This is the sample code from “Cuda C Programming Guide” Pg43~44 (using low-level API)

texture<float, cudaTextureType2D,cudaReadModeElementType> texRef;
textureReference* texRefPtr;
cudaGetTextureReference(&texRefPtr, "texRef");
cudaChannelFormatDesc channelDesc;
cudaGetChannelDesc(&channelDesc, cuArray);
cudaBindTextureToArray(texRef, cuArray, &channelDesc);

The line “cudaGetTextureReference(&texRefPtr, “texRef”);” returns an error “invalid texture reference”.
I also tried the high level API:

texture<float, cudaTextureType2D,cudaReadModeElementType> texRef;
cudaBindTextureToArray(texRef, cuArray);

Same problem.

My full test code:

texture<float, cudaTextureType2D, cudaReadModeElementType> texRef;

int main () 
	const textureReference *tref = NULL;
	checkSuccess( cudaGetTextureReference( &tref, "texRef" )  );
	return 0;

Someone help? Im in the dire need for an answer :( thanks

PS. the sample code needs to be updated for the fact cudaGetTextureReference is expecting a const pointer. you can see ive changed my code accordingly.