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:

foo.h:

int foo();

bar.cu

#include "foo.h"

__global__ void bar(int arg)

{

  return;

}

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

{

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

 return 0;

}

foo.c:

#include "foo.h"

int g_foo = 0;

int foo()

{

  ++g_foo;

  return g_foo;

}

terminal:

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

$ nvcc -o bar.o -c bar.cu 

$ 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”.