0

I recently started learning some C(watched the first 30 vidoes of "Buckys C++ Programming Tutorials " on youtube),after I thought I knew a little about the basics I went right to tutorials on making d3d hacks(fleeps if you know it) and so on.

So I have the source for what I'm trying to write and it works fine but I can't figure out why I'm getting a "LNK2019 unresolved external symbol error"

I'm pretty sure the error is my main.cpp not being able to read things I'm telling it to. (I only know this by googling and forum searching for a while.)

"Error 3 error LNK2019: unresolved external symbol "bool __cdecl CompareColour(struct tagRGBQUAD *,int,int,int,int)" (?CompareColour@@YA_NPAUtagRGBQUAD@@HHHH@Z) referenced in function "void __cdecl ScanBMP(class ScanContents *)" (?ScanBMP@@YAXPAVScanContents@@@Z) C:\Users\Sherm\Desktop\Current project\Color aimbot\Color aimbot\main.obj Color aimbot "

That is the error. I have checked my include/lib's multiple times and that main.cpp is included in the project.

Also:Here is the project files: http://www.mediafire.com/?3gy76bqvf687h4i

(Yes i could just copy paste the source i have and fix the problem but then whats the point in learning)

Heisenbug
  • 38,762
  • 28
  • 132
  • 190
  • 1
    http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix – chris May 04 '13 at 19:06
  • 2
    And no one wants to download 10MB of code. Cut it down to a short sample that exhibits the error and post it here, along with how you compile and link it. – chris May 04 '13 at 19:07
  • I'll get back to you with some answers once i thoroughly read threw the post that chris commented. – Sherman Miller May 04 '13 at 19:11
  • 1
    @ShermanMiller I would say at least 90% of 'unresolved symbol' errors we see here are explained by either 1) they forgot to write it, 2) they forgot to compile it or 3) they forgot to link it. More subtle explanations are rare indeed. – john May 04 '13 at 19:17
  • I'v looked into all that and nothing,yes im very new to C but iv been sitting here with this simple error for hours and like i said in my first post i could just copy post and boom fixed but i wnat to understand why im getting it,I think its something to do with linking my header and .cpp file but iv googled on how to do that and still getting the error =\. (edit for refrence i have the working version of what im trying to write on my other screen and i still cant figure it out lol) – Sherman Miller May 04 '13 at 19:32
  • Make sure you are learning what you want to learn. C and C++ are two very different languages. You may have enrolled in a wrong class without realizing it. – n. m. could be an AI May 04 '13 at 19:38
  • @ShermanMiller Is all your code C, or is it all C++? You seem a little confused on this point. Mixing C and C++ is possible but it brings it's own problems (including linking errors). – john May 04 '13 at 19:40
  • @John I have looked into linking and such so yes i know about this and i started this as a fresh C++ project so its all in c++. – Sherman Miller May 04 '13 at 19:47
  • js, bucky's c++ youtube video's... are not good quality tutorials. There are books. Use them. – johnathan May 04 '13 at 22:20
  • CompareColour is the function your linker cannot find. There's a few possible causes of this. 1. your not linking with the library that it's located in. 2. you declared the function in a header, but did not impliment it. Pretty much, that's it. Considering it's decorated with c++ name decorations from the MSVC compiler, and considering the spelling of color is colour, id say you have declared a function in a header, but never implemented it in your cpp file. – johnathan May 04 '13 at 22:23
  • looking at the code ... i can see exactly why your having link issues. lines 5, 7, 8, 9, and 10 of your main.cpp file. – johnathan May 04 '13 at 22:32

1 Answers1

1

In your main.cpp file your have a forward decleration for the CompareColour function, but it is never implemented. What you have there in main.cpp tells the compiler "I promise I'll tell you how to do this later, for now just assume it exists" so it creates an "external symbol" to that function. Then you "break your promise" and never tell it how to do CompareColour, so it gets a linking error because it can't link that external symbol to any code.

So take a look at the TakeScreenShot function. On line 5 there is a forward deceleration for it. Then on line 42 starts an implementation for it. So when TakeScreenShot is called on line 91 the compiler creates an "external symbol" using the information just from line 5 which points to an empty spot of code. Then when it finishes, it goes back and sees the implementation of the function on line 42 and places that at the destination of that external symbol. Then when the linker goes through the file it links those two spots of code and everything is happy. The call to CompareColor still points to empty code when the linker encounters it, since there is no implementation, and hence your error.

That was an oversimplified version of what's actually going on, but hopefully it makes sense.

Tim Sweet
  • 636
  • 5
  • 15