4

I create Console Application in VC++ 2010, and add the following code to it:

#include <d3d10.h>
#include <d3dx10.h>
#include <DxErr.h>

#pragma comment(lib, "d3d10.lib")
#pragma comment(lib, "d3dx10.lib")
#pragma comment(lib, "dxgi.lib")
#pragma comment(lib, "dxerr.lib")

int _tmain(int argc, _TCHAR* argv[])
{
    IDXGIFactory* pDXGIFactory;
    CreateDXGIFactory(IID_IDXGIFactory, ( void** )&pDXGIFactory);

    return 0;
}

Building this project, I have linker error: error LNK2001: unresolved external symbol _IID_IDXGIFactory

Now I create Console Application with MFC support, and add the same code. The build is successful. What is wrong in the first case? Why MFC project is built successfully, and non-MFC project fails?

Roman R.
  • 68,205
  • 6
  • 94
  • 158
Alex F
  • 42,307
  • 41
  • 144
  • 212

2 Answers2

9

You need to reference another library, which holds this identifier:

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

MSDN says its DXGI.lib but effectively at least Windows SDK 7.0 has it in a different library.

Roman R.
  • 68,205
  • 6
  • 94
  • 158
  • 1
    The difference is that `dxguid.lib` is DirectX SDK library (as opposed to Windows SDK), and according to MSDN the symbol is already in "core" Windows SDK. – Roman R. Mar 29 '12 at 06:24
  • windowscodecs.lib did help, however didn't solve all my errors. So, including both that and dxguid.lib, like Alex said, is what it took. Thanks! – leetNightshade Oct 31 '12 at 20:18
  • 1
    `IID_ID3D11Device` and `IID_ID3D11DeviceContext` are also found in `dxguid.lib` not in MSDN specified `D3D11.lib`. – SMUsamaShah Jun 01 '17 at 00:43
3

I had the same issue and In my case referencing #pragma comment(lib, "dxgi.lib") solved the issue.

G droid
  • 956
  • 5
  • 13
  • 36