0

When trying to compile project in vs2022, I get the error LNK2019 unresolved external symbol CreateDXGIFactory referenced in function main. I have including the win10 sdk and know that the file is linking because I am getting inline hints.

#include <iostream>

#include <dxgi.h>
#include <dxgi1_2.h>
#include <dxgi1_3.h>
#include <dxgi1_4.h>
#include <dxgi1_5.h>
#include <dxgi1_6.h>
#include <dxgicommon.h>
#include <dxgidebug.h>
#include <dxgiformat.h>

int main()
{
   UINT i = 0, j = 0, k=0;
    IDXGIFactory* pFactory = nullptr;
    IDXGIAdapter* pAdapter;
    IDXGIOutput* pOutput;
    if (CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)(&pFactory)) == S_OK)
    {
        while (pFactory->EnumAdapters(i, &pAdapter) != DXGI_ERROR_NOT_FOUND)
        {
            while (pAdapter->EnumOutputs(j, &pOutput) != DXGI_ERROR_NOT_FOUND)
            {
                ++j,k;
                pOutput->Release();
            }
            j = 0;
            ++i;
            pAdapter->Release();
        }
        std::cout << j << std::endl;
        pFactory->Release();
    }
    else  
    {
        std::cout << "Err creating dxgi factory" << std::endl;
    }
    return 0;
}

https://i.stack.imgur.com/A75rM.png

  • No, your "inline hints" are just hints taken from the header files. you need to instruct your linker to link against the dxgi libary. – Raildex Mar 13 '23 at 11:46
  • Note: libraries required to be linked in order to use particular function are listed at requirements section at official documentation https://learn.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-createdxgifactory#requirements – user7860670 Mar 13 '23 at 12:04
  • It's a common misunderstanding, the compiler finds the header file so everything must be OK? No. As well as header files, in most cases, the linker also needs to find the corresponding library files. – john Mar 13 '23 at 12:11
  • You can add ``#pragma comment(lib,"dxgi.lib")`` to your code if you don't want to add it to the project settings. For DirectX Programming, you typically want to link with ``dxgi.lib dxguid.lib`` and either ``d3d11.lib`` or ``d3d12.lib``. ``uuid.lib`` is also useful for some scenarios. – Chuck Walbourn Mar 15 '23 at 05:53

0 Answers0