Why won't nvcc show symbols? (newbie problem)

I have two files:

main.c:

[codebox]void myfunc(void);

int

main(void)

{

myfunc();

return;

}[/codebox]

and cuda.cu:

[codebox]void

myfunc(void)

{

return;

}

[/codebox]

I compile them like so:

nvcc -c cuda.cu

gcc -c main.c

(Those works fine. The next one doesn’t)

gcc -L/usr/local/cuda/lib -lcudart -o program main.o cuda.o

The last line, the linking, gives me this:

main.o: In function `main’:

main.c:(.text+0x12): undefined reference to `myfunc’

collect2: ld returned 1 exit status

Had cuda.cu been a regular c file compiled with gcc, this would’ve worked and main() would’ve seen myfunc, but with nvcc this isn’t the case. What am I doing wrong?

Note that I need to build main.c with gcc and I also need to link with gcc, so replacing gcc with nvcc is not an option right now.

you need to declare myfunc as extern “C”

Be careful.

Intel works with odd address, Nvidia GPU not.

struct {

int32_t i;

int64_t ii;

}

will have different sizes and differen offset of “ii” in your compilation.

nvcc knows about it and calls gcc with -malign-double.

Yes, nvcc calls gcc - it’s secret knowledge ;)

nvcc is just a script.

I’m waiting for someone who rewrite it in shell - for better clearance of process.

Regards,

    Sergiy

Hmmm… but as long as I just use basic types, I should be fine, right?

Thanks for the tip, both of you!