vscode c_cpp_properties setting

摘要:
vscodec_cpp_PropertiessettingC/C++插件用户项目配置。vscode/ccpp属性。Json添加了以下内容:{“version”:4,“configurations”:〔{“name”:“mingw-w64-x86_64”,“intelligSenseMode”:“gcc-x64”,“definition”:〔“DEBUG”,“_DEBUG”
vscode c_cpp_properties setting

C/C++ 插件用户工程项目配置

.vscode/c_cpp_properties.json 增加如下内容:

{
    "version": 4,
    "configurations": [
        {
            "name": "mingw-w64-x86_64",
            "intelliSenseMode": "gcc-x64",
            "defines": [
                "DEBUG",
                "_DEBUG",
                "_DEBUG_CDB",
                "UNICODE",
                "_UNICODE",
                "_FORTIFY_SOURCE=1",
                "CHECK_PTHREAD_RETURN_VALUE",
                "_FILE_OFFSET_BITS=64",
                "_LARGEFILE64_SOURCE",
                "LARGEFILE_SOURCE",
                "__cdecl=__attribute__((__cdecl__))"
            ],
            "includePath": [
                "${workspaceRoot}\\src",
                "${workspaceRoot}\\inc",
                "C:\\msys64\\mingw64\\include",
                "C:\\msys64\\mingw64\\include\\c++\\9.2.0\\backward",
                "C:\\msys64\\mingw64\\include\\c++\\9.2.0",
                "C:\\msys64\\mingw64\\x86_64-w64-mingw32\\include",
                "C:\\msys64\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\9.2.0\\include-fixed",
                "C:\\msys64\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\9.2.0\\include"
            ],
            "browse": {
                "path": [
                    "${workspaceRoot}\\src",
                    "${workspaceRoot}\\inc",
                    "C:\\msys64\\mingw64\\include",
                    "C:\\msys64\\mingw64\\include\\c++\\9.2.0\\backward",
                    "C:\\msys64\\mingw64\\include\\c++\\9.2.0",
                    "C:\\msys64\\mingw64\\x86_64-w64-mingw32\\include",
                    "C:\\msys64\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\9.2.0\\include-fixed",
                    "C:\\msys64\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\9.2.0\\include"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            },
            "windowsSdkVersion": "10.0.16299.0",
            "compilerPath": "C:\\msys64\\mingw64\\bin\\g++.exe",
            "cStandard": "c11",
            "cppStandard": "c++17"
        }
    ]
}

-----------------------------------

.vscode/launch.json 增加如下内容:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "C++ Launch (GDB)",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\msys64\mingw64\bin\gdb.exe",
            "miDebuggerArgs": "",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

.vscode/tasks.json 增加如下内容:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "BuildProject",
            "command": "C:\msys64\msys2_shell.cmd",
            "args": [
                "-mingw64",
                "-where",
                "${fileDirname}",
                "-shell",
                "bash",
                "build.sh",
                "${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "C:\msys64"
            },
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "shared",
                "showReuseMessage": true,
                "clear": false
            },
            "problemMatcher": "$gcc"
        },
        {
            "type": "shell",
            "label": "CleanProject",
            "command": "C:\msys64\msys2_shell.cmd",
            "args": [
                "-mingw64",
                "-where",
                "${fileDirname}",
                "-shell",
                "bash",
                "clean.sh",
                "${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "C:\msys64"
            },
            "group": {
                "kind": "test",
                "isDefault": true
            },
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "shared",
                "showReuseMessage": true,
                "clear": false
            },
            "problemMatcher": "$gcc"
        }
    ]
}

vscode c_cpp_properties setting第1张

vscode c_cpp_properties setting第2张

vscode c_cpp_properties setting第3张

vscode c_cpp_properties setting第4张

------------------------------------

Code-Runner 插件用户全局配置

C:UsersLSGXAppDataRoamingCodeUsersettings.json 增加如下内容:

    "code-runner.runInTerminal": true,
    "code-runner.ignoreSelection": true,
    "code-runner.executorMap": {
        "c": "cd $dir && gcc $fileName -o $fileNameWithoutExt.exe -Wall -g -Og -static-libgcc -std=c11 && $dir$fileNameWithoutExt.exe",
        "cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt.exe -Wall -g -Og -static-libgcc -std=c++17 && $dir$fileNameWithoutExt.exe"
    }

----------------------------------------

C++ 编译器支持情况表 vscode c_cpp_properties setting第5张https://zh.cppreference.com/w/cpp/compiler_support  

vscode c_cpp_properties setting第6张

--------------------------------------

查看 gcc 配置信息 echo | gcc -v -x c -E -
查看 g++ 配置信息 echo | gcc -v -x c++ -E -
查看 g++ 配置信息 echo | g++ -v -x c++ -E -

vscode c_cpp_properties setting第7张

--------------------------

注意: mingw32 不支持wWinMain作为程序入口,需要将wWinMain改为WinMain 。

C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/x86_64-w64-mingw32/lib//libmingw32.a(lib64_libmingw32_a-crt0_c.o): in function `main':
E:/mingwbuild/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crt0_c.c:18: undefined reference to `WinMain'
collect2.exe: error: ld returned 1 exit status

via https://stackoverflow.com/questions/58324230/undefined-reference-to-winmain-c-mingw

One thing to note is that Visual C++ supports a “wWinMain” entry point where the “lpCmdLine” parameter is a “LPWSTR”. You would typically use the “_tWinMain” preprocessor definition for your entry point and declare “LPTSTR lpCmdLine” so that you can easily support both ANSI and Unicode builds. However, the MinGW CRT startup library does not support wWinMain, so you’ll have to stick with the standard “WinMain” and use “GetCommandLine()” if you need to access command line arguments.

Use WinMain instead. This program doesn't use pCmdLine value, so it should compile when you change wWinMain to WinMain and PWSTR pCmdLine to PSTR pCmdLine.

via https://docs.microsoft.com/en-us/windows/win32/learnwin32/prepare-your-development-environment
via https://www.transmissionzero.co.uk/computing/win32-apps-with-mingw/

================ End

免责声明:文章转载自《vscode c_cpp_properties setting》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇linux 安装 esMy97日期控件My97DatePicker使用(备忘)下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

VSCode编译CMake工程报错c++: internal compiler error: Killed (program cc1plus)

现象 使用VSCode+CMake构建C++工程时只能编译Release版本,无法编译Debug版本。 报错提示c++: internal compiler error: Killed (program cc1plus) 解决 编译过程中内存不足 方案1:增加内存 如果在虚拟机运行Linux可以增加虚拟机的分配内存或增大swap空间 具体方法可以参考这篇文...

VSCODE 插件初探

写在前面 分享一个vscode插件background(用于改变背景)。点击直接跳到vscode插件开发步骤 做vscode的插件,很久就有这个想法了,但是一直因为这样,那样的事情耽误,放弃了N次。不过确实让我对文档有了个直观的了解。 上周末的时候因为测试妹纸要加班测试,让我也到公司加班,等待可能出现的bug这理由听着就扯淡 当然一群妹纸都到公司等着...

gcc中gdb调试工具的使用

首先,利用gcc编译源文件时添加 -g 选项生成可调试的文件,例如,要调试test.c文件,输入命令 $ gcc -g test.c -o test_gdb 生成test_gdb文件。 然后,运行命令 $ gdb test_gdb 可进入调试模式。 在调试模式中,(gdb) 表明此时可输入命令,常用的gdb调试命令如下: GDB常用命令 格式 含义 简...

Vscode + Python + Django开发环境常见问题

Vscode 越来越好用了,轻量还跨平台。 1, 主程序安装。 2. 汉化:左侧工具条的扩展菜单,搜索 chinese 第一个就是汉化包 ,安装后重启。 3. 安装Python扩展:还是扩展菜单,搜索python 一般第一个就是, 注释为:Linting,Debugging (multi-threaded, ..... 4. 我用过Kite 自动补全,还不...

可执行二进制文件的形成过程与简单调试

1) 预处理:主要对源码预编译语句(如宏定义define)和文件包含进行处理。即对宏指令替换和包含文件放置到需要编译的文件中,完成后会生成完整的C程序源文件。 2) 编译:对预处理以后文件进行编译,生成.s后缀的汇编语言文件,即该文件里是汇编语言的代码,汇编是一种更底层的语言,直接对硬盘进行操作。 3) 汇编:对汇编语言文件进行汇编,主要调用汇编处理程序来...

VS Code使用Git可视化管理源代码详细教程

前言:   随着VS Code的功能和插件的不断强大和完善,它已经成为了我们日常开发中一个必不可缺的伙伴了。在之前我曾经写过一篇SourceTree使用教程详解(一个git可视化管理神器,想要了解的话可以点击查看详情),这篇文章主要是对VS Code如何使用Git可视化管理我们的程序源代码。 VS Code简介: 官网下载地址: https://code....