How to configure VSCode in Linux for wxWidgets

Information on configuring VSCode in Linux is sparse. In addition, information on configuring VSCode to run with wxWidgets is equally sparse. So, after days of poking around I finally got a working sample. Here is how I did it:

Starting conditions

Here are the install steps:

  1. # install additional components
    # libwxgtk3.2-dev is wxWidgets
    sudo apt install git gcc g++ gdb make cmake libwxgtk3.2-dev
    # install VSCode via snap
    sudo snap install --classic code

  2. # link to wx at the root
    cd /usr/include
    sudo ln -s wx-3.2/wx wx

  3. # copy the setup.h file
    sudo cp /usr/lib/x86_64-linux-gnu/wx/include/gtk3-unicode-3.2/wx/setup.h /usr/include/wx-3.2/wx

  4. # install the C++ extensions in VSCode
    C/C++
    C/C++ Extension Pack

  5. # Add some minimal code
    Perhaps from https://docs.wxwidgets.org/3.1/overview_helloworld.html

  6. # create the json files
    Shift-Control-P (to get the configuration list)
    • select "C/C++ Edit Configure (UI)" - this will generate the c_cpp_properties.json file
    • select the main.cpp file
    • from the configuration list, select "C/C++ Debug Add Configuration" - this will generate the lauch.json file
    From the main menu, select "Terminal->Configure Tasks" - this will generate the tasks.json file

  7. # add extra include folders to c_cpp_properties.json @ the project's .vscode directory
          "${workspaceFolder}/**"
          /usr/include/wx-3.2/wx
          /usr/lib/x86_64-linux-gnu/wx/include/gtk3-unicode-3.2

  8. # Add to settings.json @ ~/.config/Code/User/settings.json
    # This will contravene the Snap properties
    "terminal.integrated.env.linux": {
          "GTK_PATH": null,
          "GIO_MODULE_DIR": null,
    },

  9. Tweak the tasks.json file to change "${file}" to "${workspaceFolder}/*.cpp"
    Tweak the tasks.json file to include items from "wx-config --cxxflags -libs"
          "-I/usr/lib/x86_64-linux-gnu/wx/include/gtk3-unicode-3.2",
          "-I/usr/include/wx-3.2",
          "-D_FILE_OFFSET_BITS=64",
          "-DWXUSINGDLL",
          "-D__WXGTK__",
          "-L/usr/lib/x86_64-linux-gnu",
          "-pthread",
          "-lwx_gtk3u_xrc-3.2",
          "-lwx_gtk3u_html-3.2",
          "-lwx_gtk3u_qa-3.2",
          "-lwx_gtk3u_core-3.2",
          "-lwx_baseu_xml-3.2",
          "-lwx_baseu_net-3.2",
          "-lwx_baseu-3.2",
    Tweak the tasks.json file to force the standard C++ library (due to snap interference)
          "-lstdc++"

Sample json files from the project's .vscode directory

c_cpp_properites.json

{
    "configurations": [
        {
            "name": "Linux",
    
        "includePath": [
              "${workspaceFolder}/**"
              "/usr/include/wx-3.2/wx/**",
              "/usr/lib/x86_64-linux-gnu/wx/include/gtk3-unicode-3.2/**"
        ],
    
            "intelliSenseMode": "linux-gcc-x64",
            "cStandard": "c17",
            "cppStandard": "gnu++17"
        }
    ],
    "version": 4
}

launch.json

{
    "configurations": [
        {
            "name": "C/C++: gcc build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: gcc build active file",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ],
    "version": "2.0.0"
}

tasks.json

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: gcc build active file",
            "command": "/usr/bin/gcc",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${workspaceFolder}/*.cpp",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}",
            
                "-I/usr/lib/x86_64-linux-gnu/wx/include/gtk3-unicode-3.2",
                "-I/usr/include/wx-3.2",
                "-D_FILE_OFFSET_BITS=64",
                "-DWXUSINGDLL",
                "-D__WXGTK__ -pthread",
                "-L/usr/lib/x86_64-linux-gnu",
                "-pthread",
                "-lwx_gtk3u_xrc-3.2",
                "-lwx_gtk3u_html-3.2",
                "-lwx_gtk3u_qa-3.2",
                "-lwx_gtk3u_core-3.2",
                "-lwx_baseu_xml-3.2",
                "-lwx_baseu_net-3.2",
                "-lwx_baseu-3.2",
                "-lstdc++"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

settings.json @ ~/.config/Code/User/

{
    "C_Cpp.default.compilerPath": "/usr/bin/gcc",
    "C_Cpp.default.compileCommands": [

        ""
    ],
    "editor.indentSize": "tabSize",
            
    "terminal.integrated.env.linux": {
        "GTK_PATH": null,
        "GIO_MODULE_DIR": null,
    },
                
    "workbench.settings.enableNaturalLanguageSearch": false,
    "workbench.settings.applyToAllProfiles": [],

}