sudo add-apt-repository ppa:ubuntu-desktop/ubuntu-make
sudo apt-get update
sudo apt-get install ubuntu-make
sudo umake ide visual-studio-code
按提示安装就OK了。
安装完成之后,在搜索框可以找到VSCode的图标。
但是不管怎么点都开不开
接着
$ cd ~/.config
$ sudo rm -rf ./Code/
然后就打开了(一脸懵逼!可能和之前安装Anocondas使用选择了安装它但是没安装成功之后就一直没管有关,总之不管什么原因,安装好之后,运行上面的代码,删除旧的配置,再运行就可以打开了。)
然而安装成功后还不算完,想要用它写程序还得安装相应的插件,需要我有什么办法呢!!!
别着急,真的有办法呢!
打开VSCode之后,点击左侧菜单栏的最下面那个,搜索想要安装的扩展,比如我这里要安装C/C++
图上我已经安装好了,这里你可以,你在国外,你家有钱开VPN,直接点install安装就好,牛逼就完事了!
如果你不能安装,那就按提示点击右下角提示的网站,单独下载扩展安装包,这个安装包是.vsix格式的(鬼知道这是什么格式),然后回到VScode安装扩展页面,点右上角的…出现下图界面选择从VSIX安装就完事了!
最后提示安装成功,美滋滋!!
接着再安装几个有用的扩展,这几个扩展不需要直接点安装就可以,我也是醉了!
Anaconda Extension Pack
C/C++ Snippets
C++ Intellisense
CMake
CMake Tools
Code Runner
Color Highlight
color-variable-replace
EPITECH C/C++ Headers
File Templates
GBKtoUTF8
Include Autocomplete
One Dark Pro
Python
RunInTerminal
Tiny Light
Vim
VS Color Picker
vscode-icons
是的,一共20个,大部分都是很有用的包,有些暂时还没用到,我都按装了,具体有什么用,怎么用,点进去自己看,都有很详细的使用介绍。
安装好之后,关掉程序重新打开,或者点一下扩展左边reload按钮(install旁边),写一段简单的C++程序,如图,成功输出!
打开刚刚编写好的 hello.cpp,然后按 F5 调试。因为是第一次调试,系统会弹出 选择环境 面板, 这里选择 C++(GDB/LLDB)。
选择运行环境后,VSCode会在工作区 .vscode 文件夹下创建 luanch.json 模板文件并打开,将文件内容修改成下图这样就OK了。
luanch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/${fileBasenameNoExtension}.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"externalConsole": true,
"MIMode":"gdb",
"preLaunchTask":"build",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
接着重新按F5调试一次,又会提示找不到“build”,点击配置任务,配置task.json模板
task.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "g++",
"args": [
"-g","${file}","-std=c++17","-o","${fileBasenameNoExtension}.out",
"-I","/usr/local/include",
"-I","/usr/include",
"-L","/usr/local/lib",
"-l","pthread",
"-l","opencv_core",
"-l","opencv_calib3d",
"-l","opencv_dnn",
"-l","opencv_features2d",
"-l","opencv_flann",
"-l","opencv_highgui",
"-l","opencv_imgcodecs",
"-l","opencv_imgproc",
"-l","opencv_ml",
"-l","opencv_objdetect",
"-l","opencv_photo",
"-l","opencv_shape",
"-l","opencv_stitching",
"-l","opencv_superres",
"-l","opencv_videoio",
"-l","opencv_video",
"-l","opencv_videostab"
]
}
]
}
保存,重新运行应该就是ok的了。
这里还有一个很重要的文件我没有动,就是setting.json ,因为它没有影响我运行程序。这个文件跟前两个文件都在你的工作空间的 .vscode 目录下,是三个很重要的配置文件。
工作空间相关设置
settings.json
{
// Controls auto save of dirty files. Read more about autosave [here](https://code.visualstudio.com/docs/editor/codebasics#_save-auto-save).
// - off: A dirty file is never automatically saved.
// - afterDelay: A dirty file is automatically saved after the configured `files.autoSaveDelay`.
// - onFocusChange: A dirty file is automatically saved when the editor loses focus.
// - onWindowChange: A dirty file is automatically saved when the window loses focus.
"files.autoSave": "onFocusChange",
// Controls the font size in pixels of the terminal.
"terminal.integrated.fontSize": 16,
// Controls the font family of the terminal, this defaults to `editor.fontFamily`'s value.
"terminal.integrated.fontFamily": "Ubuntu mono",
// Specifies the color theme used in the workbench.
"workbench.colorTheme": "Tiny Light",
// Specifies the icon theme used in the workbench or 'null' to not show any file icons.
// - null: No file icons
// - vs-minimal
// - vs-seti
"workbench.iconTheme": "vscode-icons",
// Configure glob patterns for excluding files and folders. For example, the files explorer decides which files and folders to show or hide based on this setting. Read more about glob patterns [here](https://code.visualstudio.com/docs/editor/codebasics#_advanced-search-options).
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/GPATH": true,
"**/GRTAGS": true,
"**/GTAGS": true,
"**/*.user": true,
"**/Makefile*":false,
"**/debug": true,
"**/release": true,
"**/Debug": true,
"**/Release": true,
"**/*.exe": true,
"**/*.dll": true,
"**/*.stash": true,
"**/*.bat": true,
"**/*.cmd": true,
"**/*cache": true,
"**/*.sdf": true,
"**/*.suo": true,
"**/Win32": true,
"**/ipch": true,
"**/x64": true,
"**/GeneratedFiles": true,
"**/*.db": true,
"**/*.out":true
},
// Set the executor of each language.
"code-runner.executorMap": {
"javascript": "node",
"java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
"c": "cd $dir && gcc $fileName -o $fileNameWithoutExt -lpthread -std=c11 && $dir$fileNameWithoutExt",
"cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt `pkg-config --cflags --libs opencv` -lpthread -std=c++17 && $dir$fileNameWithoutExt",
"objective-c": "cd $dir && gcc -framework Cocoa $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"php": "php",
"python": "python -u",
"perl": "perl",
"perl6": "perl6",
"ruby": "ruby",
"go": "go run",
"lua": "lua",
"groovy": "groovy",
"powershell": "powershell -ExecutionPolicy ByPass -File",
"bat": "cmd /c",
"shellscript": "bash",
"fsharp": "fsi",
"csharp": "scriptcs",
"vbscript": "cscript //Nologo",
"typescript": "ts-node",
"coffeescript": "coffee",
"scala": "scala",
"swift": "swift",
"julia": "julia",
"crystal": "crystal",
"ocaml": "ocaml",
"r": "Rscript",
"applescript": "osascript",
"clojure": "lein exec",
"haxe": "haxe --cwd $dirWithoutTrailingSlash --run $fileNameWithoutExt",
"rust": "cd $dir && rustc $fileName && $dir$fileNameWithoutExt",
"racket": "racket",
"ahk": "autohotkey",
"autoit": "autoit3",
"dart": "dart",
"pascal": "cd $dir && fpc $fileName && $dir$fileNameWithoutExt",
"d": "cd $dir && dmd $fileName && $dir$fileNameWithoutExt",
"haskell": "runhaskell",
"nim": "nim compile --verbosity:0 --hints:off --run",
"lisp": "sbcl --script"
},
// Configure file associations to languages (e.g. `"*.extension": "html"`). These have precedence over the default associations of the languages installed.
"files.associations": {
"ostream": "cpp",
"iostream": "cpp",
"cstring": "cpp",
"array": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"complex": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"list": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"fstream": "cpp",
"functional": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"istream": "cpp",
"limits": "cpp",
"memory": "cpp",
"mutex": "cpp",
"new": "cpp",
"numeric": "cpp",
"ratio": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"system_error": "cpp",
"type_traits": "cpp",
"tuple": "cpp",
"typeinfo": "cpp",
"utility": "cpp",
"valarray": "cpp",
"map": "cpp",
"atomic": "cpp",
"hash_map": "cpp",
"hash_set": "cpp",
"strstream": "cpp",
"forward_list": "cpp",
"unordered_set": "cpp",
"thread": "cpp",
"cinttypes": "cpp",
"typeindex": "cpp"
},
"cmake.configureOnOpen": true
}
c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include",
"/usr/local/include"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
大功告成,其中关于opencv的安装,以及boost库的安装,请参考相关博客就可!
谢谢观看,希望能帮到你!
参考文档:https://blog.csdn.net/u012435142/article/details/82952302