我正在嘗試使用 Visual Studio 2022 為 ARM64 平臺重建現有的 C 代碼。(該構建適用于 x86 和 x64 平臺。)大多數編譯成功,但對于一個使用一些 Win32 API 呼叫的檔案。我收到十幾條訊息,例如
Error C3861 '_InterlockedIncrement': identifier not found
Error C3861 '_InterlockedExchangeAdd': identifier not found
Error C3861 'WriteRelease8': identifier not found
Error C3861 'WriteNoFence8': identifier not found
...
我確實使用了其中一些功能(特別是InterlockedIncrement- 沒有下劃線),但不是全部。它們在 中宣告WinNT.h,通過 包含Windows.h。
為了進行調查,我從頭開始重新創建了一個虛擬專案,其中包含Windows.h和參考InterlockedIncrement. 這可以無縫編譯。我比較了所有構建設定,包括所有路徑(VC 目錄),但找不到任何顯著差異。
我也越來越
1>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppBuild.targets(514,5):
warning MSB8028: The intermediate directory (ARM64\Release\) contains files shared from another project (Formats.vcxproj). This can lead to incorrect clean and rebuild behavior.
1>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2301,5):
warning MSB3270: There was a mismatch between the processor architecture of the project being built "" and the processor architecture of the reference "System.Data", "AMD64". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.
但我找不到原因。我不確定這是否與上述問題直接相關。請注意,該專案是非托管 C 并且沒有參考,因此“ the processor architecture of the reference "System.Data", "AMD64"”似乎無關緊要。
我錯過了什么?
更新:
我在專案中發現了隱藏的參考(沒有出現在 IDE 中)并清理了它。這解決了第二個問題。(第一個仍然存在。)
uj5u.com熱心網友回復:
我終于找到了原因。這是我如何進行的:
我從整個專案中洗掉了所有檔案,除了有問題的檔案(檢查問題是否仍然存在);
我將該檔案添加到虛擬專案中(問題沒有出現在那里);
我比較了專案檔案,但這并沒有告訴我什么,因為它們太大并且在很多地方都不同;
我從檔案中洗掉了塊,每次重新編譯,直到問題消失;
我知道它與一個
#include <comdef.h>宣告有關;原始檔案(被條件限制)使用
_ARM_我的宏來啟用/禁用此平臺的某些功能。將檔案減少到 single
#include后,我注意到是否宣告宏足以觸發問題。答對了 !
事實證明,雖然沒有記錄,但這個宏是由微軟保留的,它改變了 Windows 包括的行為。
解決方法就是使用不沖突的宏。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/496371.html
