码迷,mamicode.com
首页 > 其他好文 > 详细

vscode c_cpp_properties setting

时间:2019-12-31 01:12:34      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:work   exec   config   入口   g++   however   str   des   rmi   

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.17134.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",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "CppCompile"
        }
    ]
}

 

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

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "CppCompile",
            "command": "C:\\msys64\\mingw64\\bin\\g++.exe",
            "args": [
                "-g",
                "-Og",
                "-Wall",
                "-static-libgcc",
                "-std=c++17",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "C:\\msys64\\mingw64\\bin"
            },
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "shared",
                "showReuseMessage": true,
                "clear": false
            },
            "problemMatcher": "$gcc"
        }
    ]
}

 

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

Code-Runner 插件用户全局配置

C:\Users\LSGX\AppData\Roaming\Code\User\settings.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++ 编译器支持情况表 技术图片https://zh.cppreference.com/w/cpp/compiler_support  

技术图片

 

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

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

技术图片

 

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

注意: 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

标签:work   exec   config   入口   g++   however   str   des   rmi   

原文地址:https://www.cnblogs.com/lsgxeva/p/12122271.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!