Jump to content
  • Advertisement
Sign in to follow this  
Spacemonkey49

[C++] Ray Tracing Problem

This topic is 3122 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys, I am attempting to follow the book "Ray Tracing From The Ground Up" in an attempt to make my own ray tracer and am now in Chapter 3 where we are to make a skeleton ray tracer given some code snippets and utility files. Unfortunately I get the following errors upon attempting to build the project in Visual Studio 2008: 1>------ Build started: Project: RayTracingv2, Configuration: Debug Win32 ------ 1>Compiling... 1>Matrix.cpp 1>Normal.cpp 1>Point3D.cpp 1>RGBColor.cpp 1>c:\users\spacemonkey49\documents\visual studio 2008\projects\raytracingv2\raytracingv2\rgbcolor.h(142) : warning C4244: 'return' : conversion from 'double' to 'float', possible loss of data 1>Tracer.cpp 1>c:\users\spacemonkey49\documents\visual studio 2008\projects\raytracingv2\raytracingv2\rgbcolor.h(142) : warning C4244: 'return' : conversion from 'double' to 'float', possible loss of data 1>c:\users\spacemonkey49\documents\visual studio 2008\projects\raytracingv2\raytracingv2\constants.h(20) : warning C4305: 'initializing' : truncation from 'double' to 'const float' 1>Vector3D.cpp 1>World.cpp 1>c:\users\spacemonkey49\documents\visual studio 2008\projects\raytracingv2\raytracingv2\viewplane.h(80) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data 1>c:\users\spacemonkey49\documents\visual studio 2008\projects\raytracingv2\raytracingv2\rgbcolor.h(142) : warning C4244: 'return' : conversion from 'double' to 'float', possible loss of data 1>c:\users\spacemonkey49\documents\visual studio 2008\projects\raytracingv2\raytracingv2\constants.h(20) : warning C4305: 'initializing' : truncation from 'double' to 'const float' 1>Generating Code... 1>Compiling manifest to resources... 1>Microsoft (R) Windows (R) Resource Compiler Version 6.1.6723.1 1>Copyright (C) Microsoft Corporation. All rights reserved. 1>Linking... 1>World.obj : error LNK2001: unresolved external symbol "private: static double const Sphere::kEpsilon" (?kEpsilon@Sphere@@0NB) 1>World.obj : error LNK2019: unresolved external symbol "public: void __thiscall Sphere::set_radius(double)" (?set_radius@Sphere@@QAEXN@Z) referenced in function "public: void __thiscall World::build(void)" (?build@World@@QAEXXZ) 1>World.obj : error LNK2019: unresolved external symbol "public: void __thiscall Sphere::set_center(class Point3D const &)" (?set_center@Sphere@@QAEXABVPoint3D@@@Z) referenced in function "public: void __thiscall World::build(void)" (?build@World@@QAEXXZ) 1>World.obj : error LNK2019: unresolved external symbol "public: __thiscall SingleSphere::SingleSphere(class World *)" (??0SingleSphere@@QAE@PAVWorld@@@Z) referenced in function "public: void __thiscall World::build(void)" (?build@World@@QAEXXZ) 1>World.obj : error LNK2019: unresolved external symbol "public: __thiscall Ray::~Ray(void)" (??1Ray@@QAE@XZ) referenced in function "public: void __thiscall World::render_scene(void)const " (?render_scene@World@@QBEXXZ) 1>World.obj : error LNK2019: unresolved external symbol "public: void __thiscall World::display_pixel(int,int,class RGBColor const &)const " (?display_pixel@World@@QBEXHHABVRGBColor@@@Z) referenced in function "public: void __thiscall World::render_scene(void)const " (?render_scene@World@@QBEXXZ) 1>World.obj : error LNK2019: unresolved external symbol "public: void __thiscall World::open_window(int,int)const " (?open_window@World@@QBEXHH@Z) referenced in function "public: void __thiscall World::render_scene(void)const " (?render_scene@World@@QBEXXZ) 1>World.obj : error LNK2019: unresolved external symbol "public: __thiscall Ray::Ray(void)" (??0Ray@@QAE@XZ) referenced in function "public: void __thiscall World::render_scene(void)const " (?render_scene@World@@QBEXXZ) 1>World.obj : error LNK2001: unresolved external symbol "private: static double const Plane::kEpsilon" (?kEpsilon@Plane@@0NB) 1>World.obj : error LNK2019: unresolved external symbol "public: __thiscall World::~World(void)" (??1World@@QAE@XZ) referenced in function _main 1>World.obj : error LNK2019: unresolved external symbol "public: __thiscall World::World(void)" (??0World@@QAE@XZ) referenced in function _main 1>C:\Users\Spacemonkey49\Documents\Visual Studio 2008\Projects\RayTracingv2\Debug\RayTracingv2.exe : fatal error LNK1120: 11 unresolved externals 1>Build log was saved at "file://c:\Users\Spacemonkey49\Documents\Visual Studio 2008\Projects\RayTracingv2\RayTracingv2\Debug\BuildLog.htm" 1>RayTracingv2 - 12 error(s), 6 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== And am unsure how to cope with these errors, I've looked in the MSDN knowledge base for what the link errors relate to and don't quite follow how they relate to the program at hand, any insight would be greatly appreciated. I've uploaded the project in RAR form for those would like to see what I am doing (you have to remove SingleSphere.h and Singlesphere.cpp from the project or else you will receive 23 errors). http://rapidshare.com/files/299590189/RayTracingv2.rar

Share this post


Link to post
Share on other sites
Advertisement
Those linker errors (LNK2019/LNK2001) are the linker complaining about not being able to find symbols. Basically, you have declared a method/member of a class,

class C {
void f();
};



..but you have never actually defined it, like this:

void C::f() {
// ...
}



As an example,
Quote:
1>World.obj : error LNK2019: unresolved external symbol "public: void __thiscall Sphere::set_radius(double)" (?set_radius@Sphere@@QAEXN@Z) referenced in function "public: void __thiscall World::build(void)" (?build@World@@QAEXXZ)


The linker can't find the definition of Sphere::set_radius, which is referred to (called) by World::build.

In this case, there appears to be large chunks of code missing, like from the Sphere class (only Sphere::hit is defined), and the Ray class (nothing defined!)

Are you missing parts of code?

Also, the way some methods are actually defined in header files (like Sphere::hit) is a bit strange.. you are more than likely going to get 'symbols mutiply defined' linker errors after you resolve these current ones (like from World.cpp and MyMain.cpp both including Sphere.h)

Share this post


Link to post
Share on other sites
Ya we only get snippets of the important parts in the book, so it makes it a bit hard to know what he meant to be put in, especially since you only get the final ray tracer as reference which has considerably more files and functions.

Share this post


Link to post
Share on other sites
It look like the book's website has downloads of relevant source code; that CodeVersion1.zip looked useful (it has sphere.cpp, for example!)

Share this post


Link to post
Share on other sites
Alright so I fixed a lot of the issues with the program and now have everything done pretty well but still have one issue:

1>SingleSphere.obj : error LNK2019: unresolved external symbol "public: __thiscall ShadeRec::~ShadeRec(void)" (??1ShadeRec@@QAE@XZ) referenced in function "public: virtual class RGBColor __thiscall SingleSphere::trace_ray(class Ray const &)const " (?trace_ray@SingleSphere@@UBE?AVRGBColor@@ABVRay@@@Z)
1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup

But I don't see what could be causing this, as I've defined all the functions as far as I know like the book and code snippets mention, I didn't use the full program from the site because it's the fully built tracer and I am trying to understand it from the basics all the way up to the advanced stuff and right now I am doing the basics :( If you could help me again mattd or anyone I would be grateful.

Code:

http://rapidshare.com/files/300506621/RayTracev4.rar

Share this post


Link to post
Share on other sites
I understand it's coming from this line:

ShadeRec sr(*world_ptr); // not used

But this file is from the actual site, and is required for the skeleton ray tracer so I am unsure as to what to do.

Share this post


Link to post
Share on other sites
Looks like ShadeRec is missing its destructor definition.

You sure you've got a function like
ShadeRec::~ShadeRec() {
// ...
}

somewhere?

Also, WinMain is missing.. is it meant to be a Windows application? If it's meant to be a console-based application, you'll need to change your project's settings.

I'm trying to download your RAR, however it says Rapidshare is currently overloaded, and you need to be a paid member or similar.

Share this post


Link to post
Share on other sites
Was missing ShadeRec destructor like you pointed out mattd :P

http://www.mediafire.com/?sharekey=bc90bbe59c76c2cd8d78a0e555291609e04e75f6e8ebb871

is another upload location, and I forgot which application type I set it as in Visual Studio :(

Share this post


Link to post
Share on other sites
Quote:
Original post by Spacemonkey49
I forgot which application type I set it as in Visual Studio :(

This is the option you use to check/can change. It shows where to get at it down the bottom of that page.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!