CUDA interopability and compiling the Collison example

I’m trying to get CUDA interoperability to work in OptiX. When I try to compile the Collision example project I get a bunch of linker errors. Also when I try to include in another project I get a ton of error complaining about cuda_runtime_api. Has anyone else seen these error and figure out a way to get either things to work?

2>CollisionOptiX.obj : error LNK2019: unresolved external symbol _cudaGetErrorString@4 referenced in function "private: void __thiscall CollisionScene::SimLineOfSightEye(bool,unsigned int)" (?SimLineOfSightEye@CollisionScene@@AAEX_NI@Z)
2>CollisionOptiX.obj : error LNK2019: unresolved external symbol _cudaGetLastError@0 referenced in function "private: void __thiscall CollisionScene::SimLineOfSightEye(bool,unsigned int)" (?SimLineOfSightEye@CollisionScene@@AAEX_NI@Z)
2>CollisionOptiX.obj : error LNK2019: unresolved external symbol _cudaSetDevice@4 referenced in function "private: void __thiscall CollisionScene::SimLineOfSightEye(bool,unsigned int)" (?SimLineOfSightEye@CollisionScene@@AAEX_NI@Z)
2>collision_generated_collision_CUDA.cu.obj : error LNK2019: unresolved external symbol _cudaConfigureCall@32 referenced in function _LOS_reduction_CUDA
2>collision_generated_collision_CUDA.cu.obj : error LNK2019: unresolved external symbol _cudaSetupArgument@12 referenced in function "void __cdecl __device_stub__Z13LOS_reductionPK6float4PS_jPK6float3jPKfS7_fff(struct float4 const *,struct float4 *,unsigned int,struct float3 const *,unsigned int,float const *,float const *,float,float,float)" (?__device_stub__Z13LOS_reductionPK6float4PS_jPK6float3jPKfS7_fff@@YAXPBUfloat4@@PAU1@IPBUfloat3@@IPBM3MMM@Z)
2>collision_generated_collision_CUDA.cu.obj : error LNK2019: unresolved external symbol ___cudaRegisterVar@32 referenced in function "void __cdecl __sti____cudaRegisterAll_49_tmpxft_000013e0_00000000_6_collision_CUDA_cpp1_ii_40b6c2ed(void)" (?__sti____cudaRegisterAll_49_tmpxft_000013e0_00000000_6_collision_CUDA_cpp1_ii_40b6c2ed@@YAXXZ)
2>collision_generated_collision_CUDA.cu.obj : error LNK2019: unresolved external symbol ___cudaRegisterFunction@40 referenced in function "void __cdecl __sti____cudaRegisterAll_49_tmpxft_000013e0_00000000_6_collision_CUDA_cpp1_ii_40b6c2ed(void)" (?__sti____cudaRegisterAll_49_tmpxft_000013e0_00000000_6_collision_CUDA_cpp1_ii_40b6c2ed@@YAXXZ)
2>collision_generated_collision_CUDA.cu.obj : error LNK2019: unresolved external symbol ___cudaRegisterFatBinary@4 referenced in function "void __cdecl __sti____cudaRegisterAll_49_tmpxft_000013e0_00000000_6_collision_CUDA_cpp1_ii_40b6c2ed(void)" (?__sti____cudaRegisterAll_49_tmpxft_000013e0_00000000_6_collision_CUDA_cpp1_ii_40b6c2ed@@YAXXZ)
2>collision_generated_collision_CUDA.cu.obj : error LNK2019: unresolved external symbol ___cudaUnregisterFatBinary@4 referenced in function "void __cdecl __cudaUnregisterBinaryUtil(void)" (?__cudaUnregisterBinaryUtil@@YAXXZ)
2>collision_generated_collision_CUDA.cu.obj : error LNK2019: unresolved external symbol _cudaLaunch@4 referenced in function "enum cudaError __cdecl cudaLaunch(char *)" (??$cudaLaunch@D@@YA?AW4cudaError@@PAD@Z)
Error	1	error C2143: syntax error : missing ';' before '__stdcall'	c:program files (x86)
vidia gpu computing toolkitcudav4.2includecuda_runtime_api.h	200
Error	2	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	c:program files (x86)
vidia gpu computing toolkitcudav4.2includecuda_runtime_api.h	200
Error	3	error C2143: syntax error : missing ';' before '__stdcall'	c:program files (x86)
vidia gpu computing toolkitcudav4.2includecuda_runtime_api.h	200
Error	4	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	c:program files (x86)
vidia gpu computing toolkitcudav4.2includecuda_runtime_api.h	200

I have the same issue as well. In another project where I included a optix header file and “cuda_runtime.h”, similar linker issues happened as well.

Just found out the issues with the SDK samples. You have to include cudart.lib and cuda.lib in the collision project.

Thanks, for the response. I actually figured that out recently as well. I was about to post the fix, but you already beat me to it ;-).

Yes, if you are using CMake to build the SDK samples change the CMakeLists.txt file for collision to add linking against the CUDA run time library:

target_link_libraries(collision
    nvModel
    nvCommon
    ${CUDA_CUDART_LIBRARY}
    )