当前位置:网站首页>Vscode configuration header file -- Take opencv and its own header file as an example
Vscode configuration header file -- Take opencv and its own header file as an example
2022-06-13 01:46:00 【No change of name】
stay windows Under the system , Use VS studio To configure opencv Or your own header file is very simple , There are many tutorials available online , This article will not be repeated . but VS studio The use of msvc Compilers are not cross platform , This paper mainly introduces the use of vscode To configure g++ Compile our cpp file .
Project directory
The project catalogue is as follows , When we use F5 Or call run coder When the plug-in , It will prompt us that the header file cannot be found , At this point, we need to configure the header file in the following figure , The contents of the document are as follows :
c_cpp_properties.json
{
"configurations": [
{
"name": "win",
"includePath": [
"${default}",
"${workspaceFolder}/**",
"D:/code/VScode/in",
"D:/working_soft/opencv455/build/install/include",
"D:/working_soft/opencv455/build/install/include/opencv2",
"D:/working_soft/opencv455/build/install/x64/mingw/lib",
],
"defines": [],
"compilerPath": "C:/mingw64/bin/g++.exe",
"cStandard": "c11",
"cppStandard": "c++11"
//"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
In this document, we focus on "includePath":[...], Inside are our header files and library directories , The library directory may not be added , It must be configured according to its own file storage path , Absolute paths are best , There may be a problem with the relative path . meanwhile , Pay attention to the modification "compilerPath": in g++.exe The location of the compiler .
launch.json
// https://github.com/Microsoft/vscode-cpptools/blob/master/launch.md
{
"version": "0.2.0",
"configurations": [{
"name": "g++.exe", // Configuration name , It will be displayed in the drop-down menu of startup configuration
"type": "cppdbg", // Configuration type ,cppdbg Corresponding cpptools Debugging function provided ; It can be thought that this can only be cppdbg
"request": "launch", // Request configuration type , It can be for launch( start-up ) or attach( additional )
"program": "${fileDirname}/${fileBasenameNoExtension}.exe", // The path of the program to be debugged
"args": [], // Command line parameters passed to the program during program debugging , It is usually set to empty
"stopAtEntry": false, // Set to true When the program will be suspended at the program entrance , Equivalent to the main Break it up
"cwd": "${workspaceFolder}", // Working directory when debugging program , This is the workspace folder ; Change to ${fileDirname} It can be changed to the directory where the file is located
"environment": [], // environment variable
"externalConsole": true, // by true Use separate cmd window , And others IDE Agreement ;18 year 10 Set as after month false Callable VSC Built-in terminal
"internalConsoleOptions": "neverOpen", // If not set to neverOpen, It will jump to “ Debug console ” tab , You shouldn't have to be right gdb Let's input the command manually ?
"MIMode": "gdb", // Specify the debugger for the connection , It can be for gdb or lldb. But I didn't try lldb
"miDebuggerPath": "C:/mingw64/bin/gdb.exe", // Debugger path ,Windows The following suffix cannot be omitted ,Linux Next, don't
"setupCommands": [
{ // The template comes with , It seems to show better STL Contents of container , The specific effect is self-evident Google
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": false
}
],
"preLaunchTask": "g++" // Tasks performed before debugging session start , It's usually a compiler . And tasks.json Of label Corresponding
}]
}
In this document, we focus on "miDebuggerPath": Here, select the corresponding location of your computer , Just look at the other notes .
settings.json
{
"files.defaultLanguage": "c++", // ctrl+N The default language after the new file is created
"editor.formatOnType": true, // Enter a semicolon (C/C++ End of statement identifier of ) After the automatic formatting of the current line of code
"editor.suggest.snippetsPreventQuickSuggestions": false, // clangd Of snippets There are a lot of jump points , You don't have to trigger it manually Intellisense 了
"editor.acceptSuggestionOnEnter": "off", // My personal habits , When you press enter, it must be a real line feed , Only tab To accept Intellisense
// "editor.snippetSuggestions": "top", // ( Optional )snippets At the top of the completion list , The default is inline
"code-runner.fileDirectoryAsCwd": true,
"code-runner.runInTerminal": true, // Set to false Will be in “ Output ” Medium output , Unable to input
"code-runner.executorMap": {
"c": "cd $dir && gcc '$fileName' -o '$fileNameWithoutExt.exe' -Wall -g -O2 -static-libgcc -std=c11 -fexec-charset=GBK && &'$dir$fileNameWithoutExt'",
"cpp": "cd $dir && g++ '$fileName' -o '$fileNameWithoutExt.exe' -Wall -g -static-libgcc -std=c++11 -I in -I D:/working_soft/opencv455/build/install/include -I D:/working_soft/opencv455/build/install/include/opencv2 -L D:/working_soft/opencv455/build/install/x64/mingw/lib -l libopencv_world455 -fexec-charset=GBK && &'$dir$fileNameWithoutExt'",
// "c": "cd $dir && gcc $fileName -o $fileNameWithoutExt.exe -Wall -g -O2 -static-libgcc -std=c11 -fexec-charset=GBK && $dir$fileNameWithoutExt",
// "cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt.exe -Wall -g -O2 -static-libgcc -std=c++17 -fexec-charset=GBK && $dir$fileNameWithoutExt"
"javascript": "node",
"java": "cd $dir ; javac $fileName ; java $fileNameWithoutExt",
//"c": "cd $dir ; gcc $fileName -o $fileNameWithoutExt ; $dir$fileNameWithoutExt",
//"cpp": "cd $dir ; g++ $fileName -o $fileNameWithoutExt ; ./$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",
"kit": "kitc --run"}, // Right click run code The command to run when ; Uncommented only applies to PowerShell(Win10 Default ), If there is a space in the file name, it can be compiled and run ; Note out applies to cmd(win7 Default ),PS and bash Can also be used , But it can't run when there are spaces in the file name
"code-runner.saveFileBeforeRun": true, // run code Before saving
"code-runner.preserveFocus": true, // if false,run code The back beacon will focus on the terminal . If you need to input data frequently, you can set it to false
"code-runner.clearPreviousOutput": false, // Every time run code Front emptiness belongs to code runner The terminal message of , Default false
"code-runner.ignoreSelection": true, // The default is false, The effect is to select a piece of code with the mouse and execute it separately , but C It's a compiled language , Not suitable for this use
"C_Cpp.clang_format_sortIncludes": true,
"files.associations": {
"array": "cpp",
"atomic": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"optional": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"ostream": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"typeinfo": "cpp"
}, // Adjust when formatting include The order of ( Alphabetical order )
"clang.cflags":[
"-I${workspaceRoot}/dev"
]
}
The document needs to be noted that "code-runner.executorMap":{}, It's critical , The definition here determines run coder Can the plug-in find your header file , among -I Indicates your header file path , -L Indicates the library file path ,-l( A lowercase letter L) Delegate library file , Only after the command is configured can it be used successfully run coder Call other libraries ; For other contents, please refer to the above format .
tasks.json
// https://code.visualstudio.com/docs/editor/tasks
{
"version": "2.0.0",
"tasks": [{
"label": "g++", // The name of the task , And launch.json Of preLaunchTask Corresponding
"command": "g++", // Compiler to use ,C++ use g++
"args": [
"${file}",
"-o", // Specify output file name , Without this parameter, the default output is a.exe,Linux By default a.out
"${fileDirname}/${fileBasenameNoExtension}.exe",
"-g", // Generate information about debugging
"-Wall", // Turn on extra warning
"-static-libgcc", // Static links libgcc, It's usually added
"-fexec-charset=GBK", // The generated program uses GBK code , Not adding this one will lead to Win Under the output of Chinese garbled code
"-std=c11", // C++ The latest standard is c++17, Or modify it according to your own needs
"-I", "D:/code/VScode/in",
"-I", "D:/working_soft/opencv455/build/install/include",
"-I", "D:/working_soft/opencv455/build/install/include/opencv2",
"-L", "D:/working_soft/opencv455/build/install/x64/mingw/lib",
"-l", "libopencv_world455"
], // Compiled commands , In fact, it's equivalent to VSC Help you lose these things in the terminal
"type": "process", // process yes vsc Pass all the predefined variables and escape to command;shell It's equivalent to opening first shell Reenter command , therefore args It will pass through shell Analyze it again
"group": {
"kind": "build",
"isDefault": true // Not for true when ctrl shift B It's about to be selected manually
},
"presentation": {
"echo": true,
"reveal": "always", // Whether to jump to terminal panel when executing task , It can be for always,silent,never. Specific see VSC Documents
"focus": false, // Set to true After that, you can execute task The focus is on the terminal , But for compiling C/C++ Come on , Set to true It makes no sense
"panel": "shared" // The compilation information of different files shares a terminal panel
},
// "problemMatcher":"$gcc" // This option can capture the error information in the terminal during compilation ; But because of Lint, If you open this again, there may be a double error report
}]
}
The function of this document is similar to that of the above documents , It should be noted that "args": , Same as "code-runner.executorMap":{} equally , Need configuration -I 、-L、-l Path and file , After configuring the file, use F5 You can successfully compile and run the generated executable .
About opencv
Can be directly from opencv Official website (Home - OpenCV) Download compiled opencv, Or compile it yourself opencv, If you use msvc Compilation cannot use g++ Call the compiled header file , So you can cmake gui Next use g++ Compile , Generally speaking, it will report an error , Baidu search the solution ok 了 . Recommended links :VScode build OpenCV Environmental Science - KenSporger - Blog Garden (cnblogs.com), If there are still problems, continue to Baidu .
Be sure to focus on the red content in the text , Incomplete configuration cannot be compiled .
Reference link :
边栏推荐
- Reinstall opencv and step on the pit.
- How many times does the constructor execute?
- This of phaser3 add. add. image
- Introduction to Google unit testing tools GTEST and gmoke
- Decompression and compression of chrome resource file Pak
- 如何利用您的自有数据来实现营销目标?
- Introduction to ROS runtime
- Qt实现思维导图功能(二)
- Logical operation bit operation
- leetcode743. 网络延迟时间(中等, dijkstra)
猜你喜欢
Large end storage and small end storage
五、库存查询功能的完善
Implementation of pointer linked list
6、 Implementation of warehouse out management function
路径字段是什么? ——竞价广告
Magics 23.0 how to activate and use the slice preview function of the view tool page
30: Kakfa simulates JSON data generation and transmission
Introduction to Google unit testing tools GTEST and gmoke
水管工遊戲
TensorFlow2的Conv1D, Conv2D,Conv3D机器对应的MaxPooling详解
随机推荐
[wsl2]wsl2 migrate virtual disk file ext4 vhdx
Differences among bio, NiO and AIO
The first cell of devaxpress CXGRID after inserting a row is in focus editing status
移动IPv6光猫登录的一般ip地址账号与密码,移动光猫变桥接模式
Unity jsonutility failed to serialize list
Tweets movement description and chart display
Stack stack LIFO
6、 Implementation of warehouse out management function
Note: common gadgets in project architecture
[WSL2]限制WSL2可访问的硬件资源(CPU/内存)
Using atexit to realize automatic destruct of singleton mode
Detailed understanding of white noise
pytorch : srcIndex < srcSelectDimSize
matplotlib画图中文乱码
Torch. Distributions. Normal
How to solve practical problems through audience positioning?
[andoid][step pit]cts 11_ Testbootclasspathandsystemserverclasspath at the beginning of R3_ Analysis of nonduplicateclasses fail
他山之石:a16z 的 Web3 投资版图
Crypto JS reports uglifyjs error
服务器安装jupyterlab以及远程登录配置