D3D11CreateDeviceAndSwapChain Unresolved External
Asked Answered
P

3

6

This is completely driving me insane. When I compile my program, I get the following error message:

error LNK2019: unresolved external symbol _D3D11CreateDeviceAndSwapChain@48

I know that I have all of the correct lib / and include directories (x86), and I have tracked the problem down to the fact that if I go to the definition (F12) I get two symbols, one for the DirectXSDK install directory, and one at "c:\Program Files (x86)\Windows Kits\8.0\Include\um".

For the life of me, I have no idea what to do. I have gone through all of the include / exclude directories and I can't get it to resolve, and I don't know what to do. Can anyone help me?

Protuberate answered 24/4, 2013 at 2:2 Comment(2)
Might be because those libraries have different compile flags.Sinker
You sure you're linking to D3d11.lib? Turn on verbose linking.Yakka
F
17

I ran into this error myself and solved it with Luke's suggestion in his comment.

Assuming you're using Visual Studio, try opening the properties window for your project, and navigate to Linker -> Input. Under 'Additional Dependencies' add d3d11.lib, and try linking again.

Fully answered 6/8, 2013 at 20:9 Comment(2)
Additionally you can put #pragma comment(lib, "d3d11.lib") in your engine header.Tews
That's the solution for Visual Studio 2017 Enterprise on the latest Windows 10 insider build. (Adding d3d11.lib to Additional Dependencies)Adachi
C
8

Okay. Before driving insane, check out that:

  • you linking against same architecture as your app: x86, x64, arm ( It is common gotcha =) )

    C:\Program Files (x86)\Windows Kits\8.0\Lib\win8\um\x86

    C:\Program Files (x86)\Windows Kits\8.0\Lib\win8\um\x64

    C:\Program Files (x86)\Windows Kits\8.0\Lib\win8\um\arm

  • you linking lib from the same sdk as your header ( in your source, try type in paths explicitly):

    #include "c:\Program Files (x86)\Windows Kits\8.0\Include\um\header.h"

    #pragma comment(lib, "C:\\Program Files (x86)\\Windows Kits\\8.0\\Lib\\win8\\um\\x64\\library.lib")

  • check that libs itself are fine (exist, not corrupted): uninstall old DXSDK and Win8SDK, then reinstall only one of them, try it, than another. (Also it is good idea to just copy somewhere docs and tutorials from old SDK, uninstall it and forget it at all)

  • try new #pragma linker (not #pragma lib) with verbose flag to gain some linker output:

    #define USE_OLD_DXSDK

    #ifdef USE_OLD_DXSDK

    #pragma comment(linker "c:\\path\\to\\old_sdk\\d3d11.lib -verbose")

    #else

    #pragma comment(linker, "c:\\path\\to\\new_sdk\\d3d11.lib -verbose")

    #endif

  • Go another way: Create a new small app and try to write D3D11CreateDeviceAndSwapChain stuff from scratch. Only #include and link what is needed right now and nothing else. Try to reproduce your linker error to understand why it is happens and find out how to fix it in your main app.

Happy coding!

Cherub answered 24/4, 2013 at 6:29 Comment(0)
G
0

Recheck your IDE for libs and make sure your IDE is using Unicode character set and that you're using unicode functions and strings properly. Also, check twice if \lib\x86 (or x64 if its the case), is properly added to your project's libraries.

Gittel answered 29/4, 2013 at 18:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.