• 13
• 18
• 19
• 27
• 9

# [C++] Ray Tracing Problem

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

## Recommended Posts

##### Share on other sites
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 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 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 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 on other sites
I understand it's coming from this line:

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 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 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 on other sites
Quote:
 Original post by Spacemonkey49I 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.