Search code examples
c++linuxvisual-studio-codewxwidgets

Configure g++ to build c++ with wxwidget library


I've been trying to compile and run a simple c++ program with Wxwidget in Linux but when I build it this is what I got when I try to build :

Executing task: g++ -c $(find /home/sopheak/Documents/WXWIDGET/ -type f -iregex '.*\.cpp') -g -D__WXGTK__ -D_FILE_OFFSET_BITS=64 -DWX_PRECOMP -fno-strict-aliasing -pthread -I/usr/local/lib/wx/include/gtk3-unicode-static-3.1/** -Iusr/include/** -I/usr/include/gtk-3.0/** -I/usr/include/at-spi2-atk/2.0/** -I/usr/include/at-spi-2.0/** -I/usr/include/dbus-1.0/** -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include/** -I/usr/include/gio-unix-2.0/** -I/usr/include/cairo/** -I/usr/include/pango-1.0/** -I/usr/include/fribidi/** -I/usr/include/harfbuzz/** -I/usr/include/atk-1.0/** -I/usr/include/pixman-1/** -I/usr/include/uuid/** -I/usr/include/freetype2/** -I/usr/include/libpng16/** -I/usr/include/gdk-pixbuf-2.0/** -I/usr/include/libmount/** -I/usr/include/blkid/** -I/usr/include/glib-2.0/** -I/usr/lib/x86_64-linux-gnu/glib-2.0/include/** -I/usr/include/gtk-3.0/unix-print/** -Wall
  
zsh:1: no matches found: -I/usr/local/lib/wx/include/gtk3-unicode-static-3.1/**
The terminal process "zsh '-c', 'g++ -c $(find /home/sopheak/Documents/WXWIDGET/ -type f -iregex '.*\.cpp') -g -D__WXGTK__ -D_FILE_OFFSET_BITS=64 -DWX_PRECOMP -fno-strict-aliasing -pthread -I/usr/local/lib/wx/include/gtk3-unicode-static-3.1/** -Iusr/include/** -I/usr/include/gtk-3.0/** -I/usr/include/at-spi2-atk/2.0/** -I/usr/include/at-spi-2.0/** -I/usr/include/dbus-1.0/** -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include/** -I/usr/include/gio-unix-2.0/** -I/usr/include/cairo/** -I/usr/include/pango-1.0/** -I/usr/include/fribidi/** -I/usr/include/harfbuzz/** -I/usr/include/atk-1.0/** -I/usr/include/pixman-1/** -I/usr/include/uuid/** -I/usr/include/freetype2/** -I/usr/include/libpng16/** -I/usr/include/gdk-pixbuf-2.0/** -I/usr/include/libmount/** -I/usr/include/blkid/** -I/usr/include/glib-2.0/** -I/usr/lib/x86_64-linux-gnu/glib-2.0/include/** -I/usr/include/gtk-3.0/unix-print/** -Wall'" failed to launch (exit code: 1).

Here my task.json :

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "Compile",
            "linux": {
                "command": "g++",
                "args": [
                    "-c",
                    "$(find",
                    "${workspaceFolder}/",
                    "-type",
                    "f",
                    "-iregex",
                    "'.*\\.cpp')",
                    "-g",
                    "-D__WXGTK__",
                    "-D_FILE_OFFSET_BITS=64",
                    "-DWX_PRECOMP",
                    "-fno-strict-aliasing",
                    "-pthread",
                    "-I/usr/local/lib/wx/include/gtk3-unicode-static-3.1/**",
                    "-Iusr/include/**",
                    "-I/usr/include/gtk-3.0/**",
                    "-I/usr/include/at-spi2-atk/2.0/**",
                    "-I/usr/include/at-spi-2.0/**",
                    "-I/usr/include/dbus-1.0/**",
                    "-I/usr/lib/x86_64-linux-gnu/dbus-1.0/include/**",
                    "-I/usr/include/gio-unix-2.0/**",
                    "-I/usr/include/cairo/**",
                    "-I/usr/include/pango-1.0/**",
                    "-I/usr/include/fribidi/**",
                    "-I/usr/include/harfbuzz/**",
                    "-I/usr/include/atk-1.0/**",
                    "-I/usr/include/pixman-1/**",
                    "-I/usr/include/uuid/**",
                    "-I/usr/include/freetype2/**",
                    "-I/usr/include/libpng16/**",
                    "-I/usr/include/gdk-pixbuf-2.0/**",
                    "-I/usr/include/libmount/**",
                    "-I/usr/include/blkid/**",
                    "-I/usr/include/glib-2.0/**",
                    "-I/usr/lib/x86_64-linux-gnu/glib-2.0/include/**",
                    "-I/usr/include/gtk-3.0/unix-print/**",
                    "-Wall"
                ]
            },
            "problemMatcher": [],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },
        {
            "type": "shell",
            "label": "MoveObjects",
            "linux": {
                "command": "mv",
                "args": [
                    "${workspaceFolder}/*.o",
                    "${workspaceFolder}/"
                ]
            },
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [],
            "dependsOn": [
                "Compile"
            ]
        }
    ]
}

I'm using Kali Linux and I've been trying looking for ways to build run wxwidgets library for weeks but I still couldn't find any good answer. Thanks you for helping in advance !


Solution

  • I think when using wxWidgets in VS Code on Linux, the easiest thing is to use CMake. To get started, you'll need both the CMake and CMake Tools extensions:

    enter image description here

    To get started, open your project in VS Code:

    enter image description here

    Then open the command pallet and select "CMake:Quick Start":

    enter image description here

    Then enter a name for the project that will be used in the CMake files and select executable for the project type. I used "cmakewx" for the project. After you select executable, a "CMakeLists.txt" file and a build folder will be created.

    Open the CMakeLists.txt file. In the middle of the file there should be a line looking something like:

    add_executable(cmakewx main.cpp)
    

    In my case "cmakewx" is the name I entered above for the project name. In your case, it will be the name you entered instead. Change this to

    find_package(wxWidgets REQUIRED COMPONENTS net core base)
    include(${wxWidgets_USE_FILE})
    add_executable(cmakewx main.cpp)
    target_link_libraries(cmakewx ${wxWidgets_LIBRARIES})
    

    But replace "cmakewx" with the name you chose for the project.

    Finally, open the command pallet again and select "CMake:Configure"

    enter image description here

    Now the project is ready to go. You can use buttons on the status bar for various project tasks. This area: enter image description here can be used to change the project's configuration (debug/release/etc). This area enter image description here will build the project, and these buttons enter image description here will debug and run the project.

    This may seem like a lot of steps, but when your familiar with the process it only takes about 30 seconds to get a project ready to go.


    Intellisense should start working after you configure the project. But I have seen that sometimes it doesn't. I'm not sure why. If this happens, closing and reopening the project should get intellisense working.