2010-07-21 136 views
4

Main article有一個header file和一個source file。複製這兩個文件並添加幾個頭後:無法解析的外部符號

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

//安全realease文件

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

     (*ppInterfaceToRelease) = NULL; 
    } 
} 

當我試圖編譯這個項目中,我得到一個錯誤:

錯誤1錯誤LNK2019:無法解析的外部符號__imp__DWriteCreateFactory @ 12在函數「private:long __thiscall SimpleText :: CreateDeviceIndependentResources(void)」(?CreateDeviceIndependentResources @ SimpleText @@ AAEJXZ)中引用

不知道爲什麼。所有?標題包括在內。希望你們中的一些人能夠爲此提供幫助。
謝謝。

+0

您是否爲特定包含文件的lib文件和dll文件設置了路徑? – DumbCoder 2010-07-21 09:38:32

回答

15

您需要鏈接到Dwrite.lib,其中包括DWriteCreateFactory

實施

here的文檔。底部的Requirements部分解釋了需要包含和鏈接到使用錯誤引用的函數的內容。

你也許可以通過增加線

#pragma comment(lib, "Dwrite") 
+0

+1爲您的答案。 – 2010-07-21 09:46:57

+1

固定爲我,當我添加它只是在包括dwrite.h – 2012-04-12 16:39:54

+0

這也糾正了我一樣的錯誤(簡單地在include下面添加#pragma行)在WinRT C++組件。 – ch3rryc0ke 2012-09-29 00:16:39

1

解決這個問題加入後:

#pragma comment(lib, "dwrite") 

此代碼的工作。

1

您不得不在提示鏈接到應用程序的庫列表中提到Dwrite.lib。