tags:

views:

87

answers:

2

Hello,

VS C++ 2008

I am just working through a DirectX tutorial.

In the source code had this line:

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

When I compiled everything linked ok.

However, I commented out this line and tried to include the header and library myself under properties, like this:

C/C++ - General
Additional include directories: "C:\Program Files\Microsoft DirectX SDK (August 2009)\Include"

Linker - General
Additional library directories: "C:\Program Files\Microsoft DirectX SDK (August 2009)\Lib\x64"
Linker - Input: d3d9.lib

However, I got this linker error:

1>main.obj : error LNK2019: unresolved external symbol _Direct3DCreate9@4 referenced in function _initD3D

However, when I just use the pragma I didn't get any linker errors. Only when I try and include them with the properties as above.

What is the real difference in using pragma and including the header/libraries using the properites?

Many thanks,

+1  A: 

at first, #pragma comment(lib) is just linker configuration

at second, the SDK should be in path, so dont set additional library directories (you may override it with wrong version), just add d3d9.lib to linker's input.

Yossarian
Yes. That was correct. I removed the paths and just had the name for the linkers input.
robUK
+1  A: 

As far as I know, there is no difference. pragma lib simply says to the linker to look for a specific library by name.

Also, since the path is not specified in the pragma, the linker relies on the current lib paths for your project. Try not add any path to your linker options (by default DX SDK adds paths to any visual studio installed, directly modifying the global visual studio paths. See Tools/Options/Projects and Solutions/VC++ Directories/Show Directories for Library files)

Some things to check:

  • you are indeed building for x64
  • your path is really pointing to the DX SDK (it is installed to Program Files(x86) if you are on x64)
  • verify if there are not other linker warnings
Bahbar
Thanks for the information. If I was adding a library that is not installed by as an SDK. I guess I would have to write the full path to the pragma lib?Just another question, as pragma is compiler specific. Isn't it better not using pragma? Thanks.
robUK
Yes, pragma is compiler specific. I pretty much never use it. To link against a library not added to the VS paths, you'd still try to abstract the full path, since you're likely to want to build it on some other machine, with a different configuration. So, usually, either use project-relative paths, or some environment variable-relative paths.
Bahbar