Linking problem fixed but not understood in VC++2008

Started by
6 comments, last by Defend 15 years, 4 months ago
Back into coding once more after yet another hiatus. This is how it goes with me. So, firing up DirectX once more I have done the basic initialisation steps and then try to compile. I get linker errors 1120 and 2019. Library problems, fair enough. The fix was to go to Project - Properties - Configuration Properties - Linker - Input and in the Additional Dependencies field, put "d3d9.lib". I found the solution by basically googling until something worked, but I don't really understand. I have included d3dx9.h in my header, and already added the lib and Include directories from the DirectX SDK to the VC++ Directories. Why did I have to add one particular file to the Additional Dependencies? Cheers.
Advertisement
It's because the linker needs to be told which libs to include. You told it a possible location for the lib file before by setting the directories up, the compiler could see the header and it was included directly with the header include directory already set up.

The linker just needed to be told the lib file you wanted to include, by doing what you did you told it, and then it found it in the folder. :D

before it was looking in the correct folder, it just didn't know what it was looking for. :D
Hmm.. then perhaps it is just my memory, but I don't remember ever having to bother with a second group of settings in the IDE when I was coding years ago.

Is there some sort of code that does this instead of having to tell the IDE?

One other question. The lib directory is divided into two more; one called x86 and the other, x64. Both have d3d9.lib, so how did the compiler choose?


And thanks for your quick answer.
Quote:
Is there some sort of code that does this instead of having to tell the IDE?

Sometimes, depending on your compiler (VS's supports it), but it is not portable. You're talking about linker settings, which apply to the linker, which doesn't deal with source code (rather it deals with object files produced from source code by the compiler) so it makes sense that it's not a source-code-level option.

"Telling the IDE" is the more proper way, in most cases.

Quote:
One other question. The lib directory is divided into two more; one called x86 and the other, x64. Both have d3d9.lib, so how did the compiler choose?

The IDE-level include/library directory settings are being used, not the project-level ones -- the IDE-level ones (in Options -> Projects and Solutions -> Directories) allow specification of directory paths for both the x86 platform and x64 platform. Which set of directories is used depends on which project configuration you are building.
yeah you can do it "in code" by using:

#pragma comment(lib, "requiredLibrary.lib")

As for the x86 and x64 versions of the library, I'm not too sure actually. I assume the linker knows which platform yu are compiling for from the project settings and selects the correct one. That is an assumption though, I haven't done any non-console coding in a while.

EDIT:
Ha! Clearly beaten to it there. :P
Quote:Original post by Westie007
yeah you can do it "in code" by using:

#pragma comment(lib, "requiredLibrary.lib")

As for the x86 and x64 versions of the library, I'm not too sure actually. I assume the linker knows which platform yu are compiling for from the project settings and selects the correct one. That is an assumption though, I haven't done any non-console coding in a while.

EDIT:
Ha! Clearly beaten to it there. :P


In visual studio, this is determined by the Target Machine options under Project Settings->Linker->Advanced.

Also note that '#pragma comment(lib, "requiredLibrary.lib")' is IDE specific, and rarely should ever be used (esp. since the time it takes to get to the additional dependencies isn't much more than the time it takes to type that line).

Just my 2 cents. :-P
"I'd rather know one thing, no matter how ordinary, than discourse endlessly on great issues." -- Galileo
Don't worry I agree with you F1N1TY. :D

Just couldn't be arsed to type that, thought I'd keep it short and sweet.
Ah, thanks. Actually just came here to ask if it was that Target Machine field that made the difference... talk about fast answers hehe, before I've even asked.

#pragma is definitely the bell that was trying to ring in my head. That's what I always used instead of changing linker settings. I see jpetrie's (and F1N1TY's) reasoning though and will boycott #pragma for this task. Hopefully I won't run into this problem again in another 3 years.

Thanks all for your answers. Understanding++

This topic is closed to new replies.

Advertisement