問題描述
在我從舊版 DirectX SDK 更改為 Windows SDK (Visual Studio 2015) 後,鏈接器一直在抱怨 (The linker keeps complaining after I changed from legacy DirectX SDK to Windows SDK (Visual Studio 2015)))
我剛剛刪除了包含在 DirectX SDK 中的所有標頭,然後我轉向了 Windows SDK,但是一旦我這樣做了,鏈接器就會不斷抱怨“未解析的外部符號”。鏈接器顯示大約 24 個錯誤,其中大部分錯誤是關於我什至沒有在我的遊戲中使用的函數。
鏈接器錯誤:error LNK2001: unresolved external symbol "union __m128 __vectorcall DirectX: :XMVectorMultiply(union __m128,union __m128)
error LNK2001: unresolved external symbol "union __m128 __vectorcall DirectX::XMVectorSubtract(union __m128,union __m128)
error LNK2001: unresolved external symbol "union __m128 __vectorcall DirectX::XMVector3Normalize(union __m128)
<
參考解法
方法 1:
"Unresolved symbol" means that either you directly call these functions, or they are called by functions that you are calling. Functions that you call must either be defined by source code that you compile and link into your application, or they must be defined by libraries that you link into your application.
The DirectX Math library is completely defined in the header; there is no library to link against. Their definitions are in the various DirectX Math .inl
files that are included by DirectXMath.h
.
In other words, it's virtually impossible for you to include the header file declaring these functions and not get the implementation for them.
Since I am not at your computer, I can't tell you exactly what you did to cause this state of affairs. To determine the actual cause, you should simplify the problem to the smallest possible program that reproduces the problem, such as creating a new project that only includes DirectXMath.h
and uses the function XMVectorMultiply
to perform a vector multiplication and print the result.
Once you get that simple program working, then compare it to your program and look at the differences to find the source of your error.
This is the same process you go through when debugging an application at runtime, it's just that you're debugging your build instead of your application.
(by Soon_to_be_code_master、legalize)