libraries linkage error mixing c and cuda

Hi all,
I have a c library which uses a cuda library. The C library is big, so I don’t want to change it to cuda. Each library by itself compiles properly, but when linking them together, the C lib doesn’t find the cuda lib.
In the cuda lib, I tried writing an intermediate function in a c file which calls the cuda function, the compiler links to the c file in the cuda lib, but can’t link to the cuda functions, which leads me to think that the problem is with the difference between c and cuda compiler.

When I build the executable project which uses the lib that uses the cuda lib I got the following output:
(The executable is the project called msieve, that lib that msieve is using is common, and common is using test_cuda lib.)

1>------ Build started: Project: test_cuda, Configuration: Debug Win32 ------
1>Build started 6/24/2012 7:19:11 PM.
1>InitializeBuildStatus:
1> Creating “Debug\test_cuda.unsuccessfulbuild” because “AlwaysCreate” was specified.
1>AddCudaCompileDeps:
1>Skipping target “AddCudaCompileDeps” because all output files are up-to-date with respect to the input files.
1>AddCudaCompileDeps:
1>Skipping target “AddCudaCompileDeps” because all output files are up-to-date with respect to the input files.
1>AddCudaCompilePropsDeps:
1>Skipping target “AddCudaCompilePropsDeps” because all output files are up-to-date with respect to the input files.
1>AddCudaCompilePropsDeps:
1>Skipping target “AddCudaCompilePropsDeps” because all output files are up-to-date with respect to the input files.
1>CudaBuild:
1>Skipping target “CudaBuild” because all output files are up-to-date with respect to the input files.
1>CudaBuild:
1>Skipping target “CudaBuild” because all output files are up-to-date with respect to the input files.
1>Lib:
1> All outputs are up-to-date.
1> cuda.vcxproj → C:\Users\Otniel\Dropbox\Otniel\Projects\msieve-1.50\build.vc10\Debug\test_cuda.lib
1>FinalizeBuildStatus:
1> Deleting file “Debug\test_cuda.unsuccessfulbuild”.
1> Touching “Debug\test_cuda.lastbuildstate”.
1>
1>Build succeeded.
1>
1>Time Elapsed 00:00:00.06
2>------ Build started: Project: msieve, Configuration: Debug Win32 ------
2>Build started 6/24/2012 7:19:11 PM.
2>InitializeBuildStatus:
2> Touching “Win32\Debug\msieve.unsuccessfulbuild”.
2>ClCompile:
2> All outputs are up-to-date.
2>ManifestResourceCompile:
2> All outputs are up-to-date.
2>common.lib(lanczos.obj) : error LNK2019: unresolved external symbol _transpose_64x64_cuda referenced in function _transpose_64x64
2>C:\Users\Otniel\Dropbox\Otniel\Projects\msieve-1.50\build.vc10..\bin\Win32\Debug\msieve.exe : fatal error LNK1120: 1 unresolved externals
2>
2>Build FAILED.
2>
2>Time Elapsed 00:00:01.57
========== Build: 1 succeeded, 1 failed, 4 up-to-date, 0 skipped ==========

thank you for your help.

CUDA uses a C++ frontend. This means that internally all function names are decorated according to C++ rules (necessary to encode argument information for overloaded and templated functions). These decorated names do not match up with what the C code expects, which is a simple underscore as a prefix. Declare CUDA functions you want to call from C with

extern "C"

Thank you very much for your fast reply. It solved the previous problem, but now I get the following errors:

Any ideas?

1>------ Build started: Project: msieve, Configuration: Debug Win32 ------

1>Build started 6/24/2012 9:16:45 PM.

1>InitializeBuildStatus:

1> Touching “Win32\Debug\msieve.unsuccessfulbuild”.

1>ClCompile:

1> All outputs are up-to-date.

1>ManifestResourceCompile:

1> All outputs are up-to-date.

1>test_cuda.lib(test_cuda.cu.obj) : error LNK2019: unresolved external symbol _cudaConfigureCall@32 referenced in function _transpose_64x64_cuda

1>test_cuda.lib(test_cuda.cu.obj) : error LNK2019: unresolved external symbol ___cudaRegisterFatBinary@4 referenced in function “void __cdecl __sti____cudaRegisterAll_44_tmpxft_00001244_00000000_3_test_cuda_cpp1_ii_09f9f05c(void)” (?__sti____cudaRegisterAll_44_tmpxft_00001244_00000000_3_test_cuda_cpp1_ii_09f9f05c@@YAXXZ)

1>test_cuda.lib(cuda_kernel.cu.obj) : error LNK2001: unresolved external symbol ___cudaRegisterFatBinary@4

1>test_cuda.lib(test_cuda.cu.obj) : error LNK2019: unresolved external symbol ___cudaUnregisterFatBinary@4 referenced in function “void __cdecl __cudaUnregisterBinaryUtil(void)” (?__cudaUnregisterBinaryUtil@@YAXXZ)

1>test_cuda.lib(cuda_kernel.cu.obj) : error LNK2001: unresolved external symbol ___cudaUnregisterFatBinary@4

1>test_cuda.lib(cuda_kernel.cu.obj) : error LNK2019: unresolved external symbol _cudaSetupArgument@12 referenced in function “void __cdecl _device_stub__Z22transpose_64x64_kernelPyS(unsigned __int64 *,unsigned __int64 *)” (?_device_stub__Z22transpose_64x64_kernelPyS@@YAXPA_K0@Z)

1>test_cuda.lib(cuda_kernel.cu.obj) : error LNK2019: unresolved external symbol ___cudaRegisterFunction@40 referenced in function “void __cdecl __sti____cudaRegisterAll_46_tmpxft_00000ee8_00000000_3_cuda_kernel_cpp1_ii_b82f71c0(void)” (?__sti____cudaRegisterAll_46_tmpxft_00000ee8_00000000_3_cuda_kernel_cpp1_ii_b82f71c0@@YAXXZ)

1>test_cuda.lib(cuda_kernel.cu.obj) : error LNK2019: unresolved external symbol _cudaLaunch@4 referenced in function “enum cudaError __cdecl cudaLaunch(char *)” (??$cudaLaunch@D@@YA?AW4cudaError@@PAD@Z)

1>C:\Users\Otniel\Dropbox\Otniel\Projects\msieve-1.50\build.vc10..\bin\Win32\Debug\msieve.exe : fatal error LNK1120: 6 unresolved externals

1>

1>Build FAILED.

1>

1>Time Elapsed 00:00:02.03

========== Build: 0 succeeded, 1 failed, 5 up-to-date, 0 skipped ==========

Solved it!
Everything was done in 32 bits, besides one place where the linker looked in $(CUDA_LIB_PATH) which is the path for 64 bits.
Thank you very much for you help :)