vscode c_cpp_properties setting

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"
        }
    ]
}

 

 

 

 

 

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

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

 

posted @ 2019-12-30 23:47  lsgxeva  阅读(5473)  评论(0编辑  收藏  举报