I’m afraid I’m misunderstading some basic issue about linking with nvcc. In short, nvcc wouldn’t link the compiled object files and instead throws an ‘undefined reference’ error in a situation that would be perfectly fine with C and gcc.
In order to keep it simple I’ve taken the matrix multiplication example from the docs (7.2) and added a new function called ‘test’ that does nothing: void test( void ) { } All of this is in a file test.cu
This is test2.c:
void test( void );
int main( int argc, char ** argv )
{
test( );
return 0;
}
So it really does nothing else than calling the empty function that is defined in the other file. Then both test.cu and test2.c was compiled with nvcc -c producing test.o and test2.o
which I tried linking with nvcc -o test test.o test2.o but it complained about an undefined reference to `test’.
I think it is easier if you only compile .cu files with nvcc and normal files with the appropriate compiler. Then link everything together with your normal linker and just pass it the cuda libraries: -lcuda -lcudart -lcutil, I think.
And @mfatica, I think in the code he displayed in his origianl post, that was only a function prototype with the actual function contained in a seperate file…
Eelsen, thanks also for the comment, the code actually was the whole function, an empty one, it was just for the sake of testing. Anyway Massimiliano’s suggestion works fine, BTW the linker options are only -lcuda -lcudart without -lcutil.
I’m having problems linking cutil library. Every cutil library function that I use in my code complains as an undefined reference. For example:
tmpxft_00002b99_00000000-8.i:(.text+0x6ca7): undefined reference to `cutCreateTimer’
I’ve compiled CUDA SDK and am able to run all the examples. I also have “libcutil.a”. Somehow I’m not able to link libcutil.a library. Did anyone come across this problem ?
[s]I had the same problem until I compiled the SDK/common, which you obviously have. maybe it would help to take a look at the link line, mine looks like this
I think “make verbose=1” will work, though I commented out the $(VEBOSE) on the link line.
also try doing an ls on /lib. I have libcutil.a at ~148kB.[/s]
EDIT: I should read what you wrote… make sure you have the correct -L flag, and then you might need to edit LD_LIBRARY_PATH or edit /etc/ld.so.conf and run ldconfig.