- 更新 -
- 通過 Add -> Existing Item將源檔案
settings.cpp直接添加到專案中解決了 LNK2019(因為我懷疑它找不到它)。
-- 更新問題--
- 如何指定源檔案目錄,而無需按照上面的更新中所述手動添加其中的所有檔案?這對于頭檔案顯然是可以實作的(如下所述,通過將目錄添加到設定中,這對于源檔案不一樣嗎?
-- 原始問題 --
我正在努力將一個專案從 CPython 復制到 C ,作為學習更多 C 的挑戰,但我似乎無法建立環境,以便我可以編譯測驗運行。當我構建解決方案時,它會拋出一個 LNK2019,我知道這與聯結器無法找到符號有關。我已經閱讀了許多關于 SO 的解決方案,這些解決方案說要使用檔案目錄更新屬性,但它們并沒有解決問題。
目前存在的問題是:
- 其他目錄的一些標題顯示在資源管理器中,但有些沒有,為什么?
- 找不到源檔案,因此拋出 LNK2019,無法解決,如何解決?
這是我的專案的布局:
/root
/proj-cmd
/src/main/cpp
/proj/cmd
-> main.cpp
/proj-core
/src/main/cpp/
/proj/cmd
-> command.h
-> base_command.h
-> base_command.cpp
/proj/utils
-> settings.h
-> settings.cpp
main.cpp環境測驗的內容:
// astro
#include <astro/core/util/settings.h>
// stdlib
#include <exception>
#include <string>
#include <iostream>
using namespace std;
// astro entry point
int
main(int argc, char *argv[])
{
if (conf().hasKey("APP_CWD"))
{
cout << "APP_CWD is: " << conf().getKey("APP_CWD") << endl;
}
else
{
cout << "APP_CWD was not found" << endl;
}
}
為了#include <astro/core/util/settings.h>作業,我更新了屬性中的包含目錄:

However, in the explorer only command.h and settings.h are shown, not base_command.h:

Additionally, the base_command.cpp and settings.cpp do not display in the source files either, so I updated (similar to the include directories) the source directories:

That takes care of the first issue I am noticing, but now onto LNK2019. I believe this is a related result of the former problem, in that the source files are unknown:

So following many other SO posts, I tried to update the Linker settings without success:

I'm not very familiar with the Visual Studio 2017 environment, so if somebody could provide input as to how to configure these settings so that I can compile I'd appreciate this.
uj5u.com熱心網友回復:
您需要將所有 .cpp 檔案作為現有專案添加到您的專案中。僅僅在一個目錄中不足以讓 IDE 知道編譯這些檔案。標題是通過#include 按目錄找到的,但您仍應將它們作為現有項添加到您的專案中,以便更容易在樹視圖中導航它們。
這就是您收到聯結器錯誤的原因:settings.cpp 和 base_command.cpp 中的代碼永遠不會被構建。
請參閱Microsoft 檔案
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/452671.html
標籤:c visual-studio visual-studio-2017 lnk2019
