C++專案-Using C++ on Linux in VS Code
阿新 • • 發佈:2021-07-08
基於Linux在Vscode上進行C++開發
準備工作
安裝VScode
安裝 遠端 ssh-remote
Linux環境準備
gcc -v
gdb -v
庫函式
命令: gcc -v -E -x c++ -
C++ extension
安裝 VScode外掛 C++ extension for VS Code. 配置環境寫程式碼 01.Build helloworld.cpp 程式碼 02 Running the build and Modifying tasks.json create a tasks.json file to tell VS Code how to build (compile) the program Terminal > Configure Default Build Task > Choose C/C++: g++ build active file 03.Debug helloworld.cpp create a launch.json file Run > Add Configuration... and then choose C++ (GDB/LLDB). Choose g++ build and debug active file. 04.more C/C++ configurations create a c_cpp_properties.json file
衝突和問題解決
標頭檔案包含問題 Cmake “.cmaketools.json”檔案內容去覆蓋 “c_cpp_properties.json” 要求 使vscode 能夠支援對於opencv的庫匯入和語法提示、 使gcc 支援對含有opencv原始碼的編譯、 使gdb 支援對含有opencv程式碼的可執行程式的除錯。 解決辦法: opencv的庫匯入和語法提示, 可直接通過修改.vscode配置檔案中c_cpp_properties.json實現 gcc對含有opencv原始碼的編譯, 需修改task.json中編譯命令列中加入相關標頭檔案目錄、連結庫目錄以及相關的連結庫檔案, 而這本身opencv並不自帶, 需要自行通過利用cmake編譯opencv原始檔生成,而Cmake的編譯又需要python的環境 gdb對含opencv相關程式碼的可執行除錯, 需要gdb載入支援可執行檔案中opencv相關功能的dll, 這依然是通過利用cmake編譯opencv原始檔程式碼生成的
具體配置檔案
含c++的資料夾,將會生成一個.vscode資料夾,所有的配置將在這個資料夾中進行配置 01.task.json { "tasks": [ { "type": "cppbuild", "label": "C/C++: g++ build active file", "command": "/usr/bin/g++", "args": [ "-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}", "`pkg-config", "--cflags", "--libs", "opencv`", "-I", "/usr/local/include", "-I", "/usr/local/include/opencv", "-I", "/usr/local/include/opencv2", "-L", "/usr/local/lib", "-l", "opencv_core", "-l", "opencv_imgproc", "-l", "opencv_imgcodecs", "-l", "opencv_video", "-l", "opencv_ml", "-l", "opencv_highgui", "-l", "opencv_objdetect", "-l", "opencv_flann", "-l", "opencv_imgcodecs", "-l", "opencv_photo", "-l", "opencv_videoio" ], "options": { "cwd": "${fileDirname}" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true }, "detail": "Task generated by Debugger." } ], "version": "2.0.0" } 02 launch.json { "version": "0.2.0", "configurations": [ { "name": "g++ - Build and debug active file", "type": "cppdbg", "request": "launch", "program": "${fileDirname}/${fileBasenameNoExtension}", "args": ["/data/video/video/test.mp4","/data/video/frame/"], "stopAtEntry": false, "cwd": "${fileDirname}", "environment": [], "externalConsole": false, "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "C/C++: g++ build active file", "miDebuggerPath": "/usr/bin/gdb" } ] } 03.c_cpp_properties.json { "configurations": [ { "name": "Linux", "includePath": [ "${workspaceFolder}/**", "/usr/include/c++/5", "/usr/include/x86_64-linux-gnu/c++/5", "/usr/include/c++/5/backward", "/usr/lib/gcc/x86_64-linux-gnu/5/include", "/usr/local/include", "/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed", "/usr/include", "/usr/include/opencv2", "/usr/include/opencv", "/usr/lib/x86_64-linux-gnu/" ], "defines": [], "compilerPath": "/usr/bin/gcc", "cStandard": "gnu11", "cppStandard": "gnu++98", "intelliSenseMode": "linux-gcc-x64" } ], "version": 4 }
參考:
Using C++ on Linux in VS Code https://code.visualstudio.com/docs/cpp/config-linux
小白也能懂的ubuntu下Vscode中使用C++執行opencv https://www.jianshu.com/p/41f87292b34c
opencv3.2.0實現視訊抽幀,並儲存成圖片 https://www.cnblogs.com/ilykaihui/p/8010566.html