ant2009
ant2009

Reputation: 22486

pragma and including headers/libraries

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,

Upvotes: 1

Views: 3365

Answers (2)

Bahbar
Bahbar

Reputation: 18015

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

Upvotes: 1

nothrow
nothrow

Reputation: 16168

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.

Upvotes: 4

Related Questions