Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unresolved external symbol

Main article there is a header file and a source file. After copying those two files and adding few headers:

#include <Windows.h>
#include <d2d1.h>
#pragma comment(lib, "d2d1")
#include <dwrite.h>
#include <d2d1helper.h>
#include "SafeRelease.h"

//Safe realease file

template<class Interface>
inline void
SafeRelease(
    Interface **ppInterfaceToRelease
    )
{
    if (*ppInterfaceToRelease != NULL)
    {
        (*ppInterfaceToRelease)->Release();

        (*ppInterfaceToRelease) = NULL;
    }
}

when I'm trying to compile this project I'm getting an error:

Error 1 error LNK2019: unresolved external symbol __imp__DWriteCreateFactory@12 referenced in function "private: long __thiscall SimpleText::CreateDeviceIndependentResources(void)" (?CreateDeviceIndependentResources@SimpleText@@AAEJXZ)

Have no idea why. All? headers are included. Hopefuly some of you will be able to help with this.
Thank you.

like image 587
There is nothing we can do Avatar asked Jul 21 '10 09:07

There is nothing we can do


People also ask

What is unresolved external symbol?

An unresolved symbol is one that you've declared somewhere but never defined. Usually, it means you've #included some third party library's header file but not told the linker where to find the corresponding . obj files for the library.

How do I fix unresolved external symbol?

So when we try to assign it a value in the main function, the linker doesn't find the symbol and may result in an “unresolved external symbol” or “undefined reference”. The way to fix this error is to explicitly scope the variable using '::' outside the main before using it.

What causes unresolved external symbol?

The compiler can identify when a symbol isn't declared, but it can't tell when the symbol isn't defined. It's because the definition may be in a different source file or library. If a symbol is referred to but never defined, the linker generates an unresolved external symbol error.

How do you fix undefined symbol in C?

The link-editor's -z defs option can be used to force a fatal error if any undefined symbols remain. This option is recommended when creating any shared objects. Shared objects that reference symbols from an application can use the -z defs option, together with defining the symbols by using an extern mapfile directive.


2 Answers

You need to link to Dwrite.lib, which includes the implementation of DWriteCreateFactory

See here for documentation. Requirements section at the bottom explains what you need to include and link to to use the function that the error refers to.

You could probably fix this by adding the line

#pragma comment(lib, "Dwrite")
like image 178
John Sibly Avatar answered Sep 21 '22 08:09

John Sibly


After adding:

#pragma comment(lib, "dwrite")

this code works.

like image 25
There is nothing we can do Avatar answered Sep 19 '22 08:09

There is nothing we can do