頭檔案和main程式檔案放在同一檔案夾了,預處理指令中沒有波浪線和錯誤提示,但是運行時提示“undefined reference........”錯誤,有大佬幫幫我么
uj5u.com熱心網友回復:
這是鏈接錯誤。需要在鏈接選項中添加依賴的庫檔案。
uj5u.com熱心網友回復:
靠猜是猜不出來或猜不全的。建議樓主貼全代碼和對應的編譯提示~uj5u.com熱心網友回復:
https://code.visualstudio.com/docs/cpp/config-msvcFrom the main menu, choose Terminal > Configure Default Build Task. In the dropdown, which will display a tasks dropdown listing various predefined build tasks for C++ compilers. Choose cl.exe build active file, which will build the file that is currently displayed (active) in the editor.
Tasks C++ build dropdown
This will create a tasks.json file in a .vscode folder and open it in the editor.
Your new tasks.json file should look similar to the JSON below:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "cl.exe build active file",
"command": "cl.exe",
"args": [
"/Zi",
"/EHsc",
"/Fe:",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"${file}",
“/link /LIBPATH:附加依賴庫.lib所在目錄",
“/link /IMPLIB:附加依賴庫.lib" //zhao4zhong1添加(^_^)
],
"problemMatcher": ["$msCompile"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
The command setting specifies the program to run; in this case that is "cl.exe". The args array specifies the command-line arguments that will be passed to cl.exe. These arguments must be specified in the order expected by the compiler. This task tells the C++ compiler to take the active file (${file}), compile it, and create an executable file (/Fe: switch) in the current directory (${fileDirname}) with the same name as the active file but with the .exe extension (${fileBasenameNoExtension}.exe), resulting in helloworld.exe for our example.
uj5u.com熱心網友回復:
上貼中紅字應改為“/link /LIBPATH:附加依賴庫.lib所在目錄",
“/link 附加依賴庫.lib" //zhao4zhong1添加(^_^)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/221220.html
標籤:C語言
上一篇:[運維] 解決centos8 docker無法訪問公共網路的問題
下一篇:編譯原理 詞法分析
