問題描述
鏈接器給出了我在我的應用程序中根本沒有使用過的函數的錯誤 (Linker gives errors about a function that i have not used in my application at all)
鏈接器不斷顯示關於我的應用程序中未使用的函數的一堆錯誤。我唯一做的就是將標頭從 DirectX SDK 更改為 Windows SDK,我還下載了 DirectXTK 的包,這樣我就可以使用 WICTextureLoader.h
和 DDSTextureLoader.h
這裡是一些鏈接器錯誤。
error LNK2001: unresolved external symbol "union __m128 __vectorcall DirectX::XMVectorMultiply(union __m128,union __m128)
error LNK2001: unresolved external symbol "void __vectorcall DirectX::XMVectorSinCos(union __m128 *,union __m128 *,union __m128)
錯誤 LNK2001:無法解析的外部符號“ union __m128 __vectorcall DirectX::XMVectorSet(float,float,float,float)
我不確定這裡發生了什麼。在我的應用程序中,我根本沒有調用 XMVectorMultiply()
或 XMVectorSinCos()
。我已經在我的項目中鏈接了適當的庫和頭文件,但這仍然不能解決問題。什麼可能導致這些鏈接器錯誤?
(如果您需要更多相關信息,請直接詢問)
以下只是我的代碼的一部分(我沒有包含所有代碼,因為我有大約 2000 行代碼):
/code> 在我的應用程序中。我已經在我的項目中鏈接了適當的庫和頭文件,但這仍然不能解決問題。什麼可能導致這些鏈接器錯誤?(如果您需要更多相關信息,請直接詢問)
以下只是我的代碼的一部分(我沒有包含所有代碼,因為我有大約 2000 行代碼):
/code> 在我的應用程序中。我已經在我的項目中鏈接了適當的庫和頭文件,但這仍然不能解決問題。什麼可能導致這些鏈接器錯誤?(如果您需要更多相關信息,請直接詢問)
以下只是我的代碼的一部分(我沒有包含所有代碼,因為我有大約 2000 行代碼):
#pragma comment (lib, "dinput8.lib")
#pragma comment (lib, "dxguid.lib")
#pragma comment (lib, "D3D11.lib")
#pragma comment (lib, "d3dcompiler.lib")
#include <windows.h>
#include <D3D11.h>
#include <dinput.h>
#include <D3Dcompiler.h>
#include <sstream>
#include <SimpleMath.h>
#include <DirectXMath.h>
#include <DDSTextureLoader.h>
#include <WICTextureLoader.h>
#include <SpriteBatch.h>
#include <SpriteFont.h>
void Create_Camera_View_Space()
{
camPosition = DirectX::XMVectorSet(0.0f, 2.0f, ‑12.5f, 0.0f);
camDirection = DirectX::XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f);
camUp = DirectX::XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
CameraView = DirectX::XMMatrixLookAtLH(
camPosition,
camDirection,
camUp
);
}
void Create_Camera_Projection_Space()
{
CameraProjection = DirectX::XMMatrixPerspectiveFovLH(
0.4f * 3.14f,
(float)400 / 400,
1.0f,
10000.0f
);
}
void Create_World_Space_for_Ground()
{
DirectX::XMMATRIX Translation;
DirectX::XMMATRIX Rotation;
DirectX::XMMATRIX Scale;
DirectX::XMMATRIX Input_Rotation_X;
DirectX::XMMATRIX Input_Rotation_Z;
GroundWorld = DirectX::XMMatrixIdentity();
Scale = DirectX::XMMatrixScaling(500.0f, 10.0f, 500.0f);
Translation = DirectX::XMMatrixTranslation(0.0f, 10.0f, 0.0f);
GroundWorld = Scale * Translation;
}
這是我使用 DirectXMath.h
中的函數的幾次,但鏈接器顯示來自該特定標頭的錯誤..
參考解法
方法 1:
The most likely issue here is that you are building the various libraries in question with different settings, compilers, or paths.
__vectorcall
is a calling convention supported by VS 2013 or later and is used by DirectXMath in the Windows 8.1 SDK and the Windows 10 SDK if it is supported by your compiler. As DirectXMath is all inline, you have to be consistent about making sure all your use of DirectXMath in the same EXE or DLL is using the same version of the headers and the same version of the compiler.
This is one of the reasons why DirectX Tool Kit provides compiler specific vcxproj
files to ensure this is kept in sync.
As your project previously used the legacy DirectX SDK, you probably have some lingering Preprocessor macros and VC++ Directories settings that need cleaned up. You might try doing a diff of your vcxproj
file with DirectXTK_Desktop_2015.vcxproj
.
You can also have problems if you are building your x86 config with
/arch:IA32
or/arch:SSE
rather than/arch:SSE2
which is what is used for the DirectX Tool Kit library builds.A similar mismatch can happen if you try to use
_XM_NO_INTRINISCS_
in your project which does not match how DirectX Tool Kit is built.
(by Soon_to_be_code_master、Chuck Walbourn)