开发者

Unresolved external symbol referenced in function

I realize this is a hard one to answer without providing you with huge amounts of code (which I'll try to spare you).

Essentially i'm getting this error in class X, which #includes the class Y header. The class Y header has three definitions for getters

// Getters
static ID3D10Device* PDevice();
static ID3D10Buffer* PBuffer();
static ID3D10Buffer* IBuffer();

I get three identical errors, all occur in class X. so essentially the error is:

Unres开发者_JAVA百科olved external symbol ID3D10Device* PDevice() referenced in function (constructor of class X)

sorry if that's a bit vague. Any idea why this might be happening? I've googled it but I can only really make an educated guess as to what this error is.


First of all this is a linker error. This linker error means that the mangled name PDevice et al is not found.

Can you make sure that you have an implementation of a function that matches the definition? Also, maybe obvious but just check that you actualy have an implementation. If your implementation is in an external lib, be sure you have included the other lib in your linker.

Hope that helps!


Make sure the files that contain the definition and implementation of class Y are added to the project, so that the linker finds the symbols in the Y.o file


Make sure you set the dependencies right (add the lib file). In Visual Studio you can do so by Properties -> Linker -> Input -> Additional Dependencies. In the textbox you can now enter the name of your .lib file.


Another reason this can happen is when both C and C++ source files are used to create a binary. The compiler uses a different naming mechanism for C symbols vs C++ symbols. Please read the "Adding C++ To The Picture" section in this great article. One reason for example is function overloading in C++. The symbol name of the function includes the function signature (argument types and their order). To quote from the article, "all of the information about the function signature is mangled into a textual form, and that becomes the actual name of the symbol as seen by the linker." So, when C code file needs to call a function defined in a C++ file, the C code's object file only mentions the name of that C++ function (doesn't include function signature). The C++ object file however contains the mangled name (which includes the function signature). Hence, the linker reports an "error LNK2019: unresolved external symbol FOO_CPP_FUNC referenced in BAR_C_FUNC". The solution suggested there is to add an extern "C" around the declaration & definition of the C++ function.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜