error LNK2019: unresolved external symbol _D2D1CreateFactory@16

  • Thread starter Thread starter Abcadlo
  • Start date Start date
A

Abcadlo

Guest
I am working my way through MSDN's Windows Graphics guide from Learn to Program for Windows in C++. I have downloaded Direct2D Circle Sample project which works fine. Just to make sure I've got everything right I tried to replicate myself Direct2D Circle by "upgrading" BaseWindow Sample (Direct2D Circle is derived from BaseWindow).

The problem is that as soon as I put in BaseWindow



#include<d2d1.h>

ID2D1Factory *pFactory; //MainWindow class
MainWnd() : pFactory(NULL) {};

if (FAILED(D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &pFactory))) { //inside case WM_CREATE:
return -1;}





I get this error message:

1>main.obj : error LNK2019: unresolved external symbol _D2D1CreateFactory@16 referenced in function "long __cdecl D2D1CreateFactory(enum D2D1_FACTORY_TYPE,struct _GUID const &,void * *)" (?D2D1CreateFactory@@YAJW4D2D1_FACTORY_TYPE@@ABU_GUID@@PAPAX@Z)
1>C:\Users\JP\Documents\Visual Studio 2010\Projects\FirstWnd\Debug\FirstWnd.exe : fatal error LNK1120: 1 unresolved externals

I've found Unresolved Symbol?? thread where Somesh Nanda describes the same problem. The solution mentioned over there is to link D2d1.lib which actually solves the problem. The first thing I did after finding the solution was to look if D2d1.lib is present in "Additional dependencies" of Direct2D Circle to confirm this is the actual problem. Surprisingly there was no link to D2d1.lib in that project.

Just to double check if the problem is caused by any settings in project properties, I have copied the code from Direct2D Circle over the code in my version of BaseWindow. I didn't add D2d1.lib into "Additional dependencies" and I didn't do any other changes. The code compiled OK.

The question:

Why does Direct2D Circle compile fine without D2d1.lib whereas my version of BaseWindow gives me error described above? As Direct2D Circle code works fine when copied over into BaseWindow it suggests that the answer is somewhere in the code itself.

Continue reading...
 
Back
Top