[英]Compiling C++ with C codes on VS Code using G++ compiler
我的案例如下:我在 Microsoft Visual Studio 上制作了一個 GUI 程序(基於 wxWidgets),其中該代碼運行良好,混合了 C++ 和 C 文件,基本上 C 文件,基本上是 Z0D61F8370CAD1D412F80B84D143E1 文件我不能做的事情很少,但我不能丟棄它們。 very beginner with C++ OOP - I have OOP background from Java which I feel far different than C++ - but I can deal with it to certain extent. 無論如何,該程序在 Visual Studio 2019 上運行良好,但是當我將它放在另一台沒有安裝 Visual Studio 的計算機上時,它開始觸發丟失的.dll
經過少量研究我發現這是由於該計算機上缺少 Visual Studio 安裝而且我沒有安裝這些.dll
文件的管理員權限。 我在 VS Code 上尋找重建文件,我使用了 g++ 編譯器,所以我需要使用 MinGw 編譯器配置 wxWidgets。 我設法使 wxWidgets 上的 Hello World 代碼工作。 當我運行我的代碼經過一番掙扎后它沒有工作我消除了任何錯誤,但是當我構建調試/發布代碼時,它在終端上得到了什么:
C:\Users<USER>\AppData\Local\Temp\ccUB3ReN.o: In function
ZN5cMainC2Ev
: C:/Users//Desktop/wxTest/src/cMain.cpp:13: undefined reference toBus_Construct
C:/Users// Desktop/wxTest/src/cMain.cpp:13: undefined reference toDecker_Construct
C:\Users<USER>\AppData\Local\Temp\ccUB3ReN.o: In functionZN5cMain16CalculateClickedER14wxCommandEvent
: C:/Users//Desktop/wxTest/src/ cMain.cpp:426:未定義對getCG
C:/Users//Desktop/wxTest/src/cMain.cpp:442 的引用:未定義對getCGz
C::/Users//Desktop/wxTest 的引用對getPassCGX
C:/Users//Desktop/wxTest/src/cMain.cpp:455 的未定義引用:對getPassCGY
C:/User 的未定義引用 s//Desktop/wxTest/src/cMain.cpp:456: 未定義對getPassCGZ
C:/Users//Desktop/wxTest/src/cMain.cpp:457: 未定義引用totalCG
Z0D61F8370CAD1D412F80B85:/4D143Ew2 /src/cMain.cpp:470: 未定義對delay
的引用 C:/Users//Desktop/wxTest/src/cMain.cpp:528: 未定義對freeSeats
的引用 C:/Users/w/Desktop/Desktop// :530: undefined reference tofreeSingleDecker
C:\Users<USER>\AppData\Local\Temp\ccUB3ReN.o: In functionZN5cMain19GenerateGroupsClickER14wxCommandEvent
: C:/Users//Desktop/wxTest/src/cMain.cpp:622: undefined reference toinitSingleDecker
C:/Users//Desktop/wxTest/src/cMain.cpp:627: undefined reference toinitSeats
collect2.exe: error: ld returned 1 exit status The terminal process "C:\Windows\System32\Windo wsPowerShell\v1.0\powershell.exe -Command C:<USER>\Softwares\MinGW\mingw32\bin\g++.exe -g C:\Users<USER>\Desktop\wxTest\src* .cpp C:\Users <USER>\Desktop\wxTest\src* .c -o C:\Users<USER>\Desktop\wxTest\build\debug\cApp.exe -I C:\Users<USER>\Desktop\wxTest\include -I C:\wx\wxWidgets-3.1.5\include -I C:\wx\wxWidgets-3.1.5\lib\gcc_dll\mswud -L C:\wx\wxWidgets-3.1.5\lib\gcc_dll -l wxmsw31ud_core - l wxbase31ud" 以退出代碼終止:1
我注意到的是 ZN5cMainC2Ev 的一些錯誤名稱,它最初是 class 名稱ZN5cMainC2Ev
。 我認為訣竅在於task.json
arguments:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "Debug",
"command": "C:\\Amir\\Softwares\\MinGW\\mingw32\\bin\\g++.exe",
"args": [
"-g",
"${workspaceFolder}\\src\\*.cpp",
"-o",
"${workspaceFolder}\\build\\debug\\${fileBasenameNoExtension}.exe",
"-I",
"${workspaceFolder}\\include",
"-I",
"C:\\wx\\wxWidgets-3.1.5\\include",
"-I",
"C:\\wx\\wxWidgets-3.1.5\\lib\\gcc_dll\\mswud",
"-L",
"C:\\wx\\wxWidgets-3.1.5\\lib\\gcc_dll",
"-l",
"wxmsw31ud_core",
"-l",
"wxbase31ud",
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "compiler: C:\\Amir\\Softwares\\MinGW\\mingw32\\bin\\g++.exe"
},
{
"type": "shell",
"label": "Release",
"command": "C:\\Amir\\Softwares\\MinGW\\mingw32\\bin\\g++.exe",
"args": [
"${workspaceFolder}\\src\\*.cpp",
"${workspaceFolder}\\src\\BusCalcs.c",
"${workspaceFolder}\\src\\CG_Engine.c",
"${workspaceFolder}\\src\\Helper.c",
"-o",
"${workspaceFolder}\\build\\release\\${fileBasenameNoExtension}.exe",
"-I",
"${workspaceFolder}\\include",
"-I",
"C:\\wx\\wxWidgets-3.1.5\\include",
"-I",
"C:\\wx\\wxWidgets-3.1.5\\lib\\gcc_dll\\mswu",
"-L",
"C:\\wx\\wxWidgets-3.1.5\\lib\\gcc_dll",
"-l",
"wxmsw31u_core",
"-l",
"wxbase31u",
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "compiler: C:\\Amir\\Softwares\\MinGW\\mingw32\\bin\\g++.exe"
}
]
}
通過將.C
文件重命名為.CPP
文件解決了這個問題,它可以為調試和發布正確構建,並且我的應用程序工作正常,但是當我在另一台計算機上運行它時,我發現丟失的.dll
比我以前得到的要多從 VS2019 版本開始,我認為我現在的問題是處理如何優化我在任何計算機上安裝應用程序。
謝謝大家。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.