problem making shared library works with gcc but not nvcc

Hello:
I am having a difficult time making a shared library. Using a simple example I can successfully get it to work using just gcc, but I cannot get a similar example to work when it is compiled using nvcc. Maybe I am making a silly error, but I can’t find it, even after reading other posts on the subject. With every try, I get a “undefined reference” error.

The files are given below. Any assistance? Thanks, John

//==============================================================
// here is my program, saved in a file called main.c

#include <stdio.h>
#include “cvm_dist.h”

int main()
{
run_test(5);
printf(“\nhello\n”);
return 0;
}

//==============================================================
// here is my header file, saved in a file called cvm_dist.h

int run_test(int pass);

//==============================================================
// here is my cuda code, saved in a file called cvmDist.cu

#include <stdlib.h>
#include <stdio.h>
#include <cuda.h>
#include <cublas.h>
#include “cvm_dist.h”

int run_test(int pass)
{
printf(“\nIn run_test\n”);
return pass;
}

//==============================================================
// here is my nvcc command

nvcc --shared --compiler-options ‘-fPIC -Wall’ -o libcvm.so cvmDist.cu -L/usr/local/cuda/lib -lcublas

//==============================================================
// the results are:
$ ldd libcvm.so
linux-vdso.so.1 => (0x00007fff43bff000)
libcublas.so.2 => /usr/local/cuda/lib/libcublas.so.2 (0x0000000000312000)
libcudart.so.2 => /usr/local/cuda/lib/libcudart.so.2 (0x0000000000ced000)
libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x0000000000f2a000)
libm.so.6 => /lib64/libm.so.6 (0x00000000c4954000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x000000000122a000)
libc.so.6 => /lib64/libc.so.6 (0x0000000001438000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x000000000178f000)
libdl.so.2 => /lib64/libdl.so.2 (0x00000000019aa000)
librt.so.1 => /lib64/librt.so.1 (0x0000000001bae000)
/lib64/ld-linux-x86-64.so.2 (0x0000003441e00000)

// but then, a problem:

$ gcc main.c -lcvm -o runme -L/home/john/Bfactor/CUDA/test1/test2
/tmp/ccgQ7Utv.o: In function main': main.c:(.text+0xa): undefined reference to run_test’
collect2: ld returned 1 exit status

OK, I found the problem. I needed to enclose my *.cu code in the following directives:

#ifdef __cplusplus
extern “C” {
#endif

// code here

#ifdef __cplusplus
}
#endif