Link problems

I was getting link errors (undefined reference) when linking my object files on a 64-bit platform. I made a very simple program to try to figure out the problem but I still get link errors that make no sense. Here are the files:


int foo();

#include "foo.h"

__global__ void bar(int arg)




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


  bar<<<32, 32>>>(foo());

 return 0;



#include "foo.h"

int g_foo = 0;

int foo()



  return g_foo;



$ nvcc -o foo.o -c foo.c

$ nvcc -o bar.o -c 

$ nvcc -o foobar foo.o bar.o 

bar.o: In function `main':

tmpxft_00000fd7_00000000-9.i:(.text+0x5d): undefined reference to `foo()'

collect2: ld returned 1 exit status

Why am I getting an undefined reference?

Scratch that, I forgot extern “C”.