2010-07-21 135 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。