Linux學習Progect第三期

失敗歷程回顧

首先,爲了完成本期任務,我在自己之前自行安裝的 Ubuntu18.04 系統上掙扎了一上午。主要遇到了三大問題。

無法安裝 build-essential

一旦我試圖安裝 build-essential 或者是 g++/gcc,都會出現類似的提示

“g++ : Depends: g+±4.8 (>= 4.8.2-5~) but it is not going to be installed”

據說,原因是即將要安裝的軟件對某些其他軟件的第幾版本有依賴(可能那些軟件高低版本間不兼容),所以造成了十分尷尬的局面,網上還提供了一些所謂的“降級安裝方案”,但是我嘗試後發現並不能解決問題。

無法安裝 g++

在探索的過程中,無法安裝 g++ 還分爲兩種情況,一種是上面所述情況,另一種會有如下提示

E: Couldn’t find package g

這種時候一般是軟件源的問題了。不過我嘗試過更換各種源也都沒有解決問題,更可能是因爲我在私自篡改 sources.list 文件的時候沒有正確操作。下面給出我之前根據阿里雲換的源:(https://yq.aliyun.com/articles/704603)

deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse

後來根據學長建議,將 trusty 換成了 xenial,但是依舊沒有解決問題。

VScode無法正確識別 includePath

這是我破罐子破摔,不打算安裝 g++,打算直接利用系統自帶的低級版本 gcc 進行編譯中遇到的問題。在 c_cpp_properties.json 中填寫的 includePath 並沒有起效,導致下述錯誤提示不斷出現

fatal error: stdio.h: No such file or directory

後據學長提示,如果正確配置好的話是不需要配置這個文件的。遂至此放棄,重裝了 Ubuntu16.04 系統。

完成任務歷程

重裝系統之後,一切變得順利起來。

首先當然是重新安裝了 vim 和 git 等軟件。

然後熟練地重裝了 VScode 及相關插件後,馬上創建 helloworld 目錄,在其下創建 test.c,並編寫代碼

#include<stdio.h>

int main()
{
    printf("Hello world!\n");

    return 0;
}

按 F5 嘗試編譯運行,馬上就要求我配置 launch.json。但是事實上,自動生成的這個 launch.json 文件已經十分完善,不需要我進行修改(實在是比 Windows 上方便多了)

{
“version”: “0.2.0”,
“configurations”: [
{
“name”: “gcc-5 build and debug active file”,
“type”: “cppdbg”,
“request”: “launch”,
“program”: “fileDirname/{fileDirname}/{fileBasenameNoExtension}”,
“args”: [],
“stopAtEntry”: false,
“cwd”: “${workspaceFolder}”,
“environment”: [],
“externalConsole”: false,
“MIMode”: “gdb”,
“setupCommands”: [
{
“description”: “Enable pretty-printing for gdb”,
“text”: “-enable-pretty-printing”,
“ignoreFailures”: true
}
],
“preLaunchTask”: “gcc-5 build active file”,
“miDebuggerPath”: “/usr/bin/gdb”
}
]
}

然後選擇了編譯方式後,編輯器又自動生成了對應的 task.json 文件

{
“tasks”: [
{
“type”: “shell”,
“label”: “gcc-5 build active file”,
“command”: “/usr/bin/gcc-5”,
“args”: [
“-g”,
file","o","{file}", "-o", "{fileDirname}/${fileBasenameNoExtension}”
],
“options”: {
“cwd”: “/usr/bin”
}
}
],
“version”: “2.0.0”
}

最後,回到源文件 test.c,在 return 0; 上面添加一個斷點,隨即 F5 調試。終端裏成功顯示結果。

最後,回到源文件 test.c,在 return 0; 上面添加一個斷點,隨即 F5 調試。終端裏成功顯示結果。
在這裏插入圖片描述

發佈了4 篇原創文章 · 獲贊 0 · 訪問量 325
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章