Ray Tracer VS2005 project compilation. The linker complains!

Hey guys,

I’ve been trying to port a free, originally Unix-based, ray tracer to Windows. It was written by Eric Rollins and can be found here: http://eric_rollins.home.mindspring.com/ray/cuda.html

I contacted the author but he didn’t have a Visual Studio project for it. I’ve therefore been trying to do the conversion myself but get the linker errors shown below. The project is attached to this post, and is based off of the custom CUDA wizard written by Zhao Kaiyong.

I’m doing this for academic research and plan to email any successful attempt to the original author.

I’m a CUDA newcomer… and some help here would be great :)

Thanks!

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

1>Linking...

1>ray_kernel.obj : error LNK2005: __Z5V3MulP6float4S0_S0_ already defined in ray.obj

1>ray_kernel.obj : error LNK2005: __Z5V3AddP6float4S0_S0_ already defined in ray.obj

1>ray_kernel.obj : error LNK2005: __Z5V3SubP6float4S0_S0_ already defined in ray.obj

1>ray_kernel.obj : error LNK2005: __Z5V3DotP6float4S0_ already defined in ray.obj

1>ray_kernel.obj : error LNK2005: __Z15V3SquaredLengthP6float4 already defined in ray.obj

1>ray_kernel.obj : error LNK2005: __Z8V3LengthP6float4 already defined in ray.obj

1>ray_kernel.obj : error LNK2005: __Z11V3NormalizeP6float4 already defined in ray.obj

1>ray_kernel.obj : error LNK2005: __Z11V3MulScalarP6float4fS0_ already defined in ray.obj

1>ray_kernel.obj : error LNK2005: ___device_stub__Z6kernelP8RayStatePm already defined in ray.obj

1>LIBCMTD.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup

1>Debug\ray.exe : fatal error LNK1120: 1 unresolved externals

1>Build log was saved at "file://d:\Program Files\NVIDIA Corporation\NVIDIA CUDA SDK\projects\ray\ray\Debug\BuildLog.htm"

1>ray - 11 error(s), 0 warning(s)

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

ray.zip (53.5 KB)

Right click the ray_kernel.cu and set the tool to “custom build tool”.
This will take care of most of them im guessing.

Hi Korax,

Since you are using VS2005, no need for rule files.

Instead you can specify the following in the custom build rule (Right click your .cu file in solution explorer -> properties -> configuration properties -> Custom build setup -> general -> command Line)

(CUDA_BIN_PATH)\nvcc.exe" -ccbin "(VCInstallDir)bin” -c -D_DEBUG -DWIN32 -D_CONSOLE -D_MBCS -Xcompiler /EHsc,/W3,/nologo,/Wp64,/Od,/Zi,/RTC1,/MTd -I"(CUDA_INC_PATH)" -I"(NVSDKCUDA_ROOT)/common/inc" -I./ -o (ConfigurationName)\ray.obj ray.cu [/b] and for emulator debug [b] "(CUDA_BIN_PATH)\nvcc.exe" -deviceemu -ccbin “(VCInstallDir)bin" -c -D_DEBUG -DWIN32 -D_CONSOLE -D_MBCS -Xcompiler /EHsc,/W3,/nologo,/Wp64,/Od,/Zi,/RTC1,/MTd -I"(CUDA_INC_PATH)” -I"(NVSDKCUDA_ROOT)/common/inc" -I./ -o (ConfigurationName)\ray.obj ray.cu

I have modified your .vcproj file. (Attached herewith). My compilation attempt failed since I don’t have any SDL Libraries.
[attachment=6638:attachment]

Anyway I think it will compile in your setup without any trouble. Also note that there is not need to build the ray_kernel.cu file due to the statement #include <ray_kernel.cu> in your ray.cu file.

However I would prefer a .cpp and a .cu file (ray.cpp and ray_kernel.cu)
Which will be much easier to maintain.

:wave: Bye…

~Sibi
ray.zip (9.28 KB)

Sibi and Aelleur, thank you very much for the help.

Yes, 99% of the linker errors are now gone, and it also gets past the SDL-related part. However, now I am attempting to get past:

LIBCMTD.lib(crt0.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup

I’ve read on non-CUDA-related forums that changing the linker subsystem to “Console” or “Windows” usually fixes this problem, but it isn’t helping in my situation. I’m running WinXP 32-bit.

Any last ideas? Everything should be fine after this.

Thanks again,

  • Korax

sdl is very picky about the signature of the main function. Check sdl forums about how to declare it correctly, i dont remember off the top of my head.

It is as simple as that, You don’t have any main function in your entire source code.

simply adding the following code will help you to get out of Linker error LNK2019

int main(int argc, char* argv)
{
// Your code to initialize CUDA and SDL libraries.
// Calls to invoke ray tracer
// Clean up and exit
}

After all SDL is a library isn’t it? There is a very little chance for a library to have a main function in it. I guess you will have to write your own main function.

i’ve been using your source code (really helpful by the way - thanx :thumbup: )
to find out that debugging results to emulation - GPU is not used…
is that normal (for debug || win32)?

You can use -deviceemu option in either configurations (Debug or Release)
There is no problem in setting this compiler flag with any visual studio configuration.