配置 g++ 以使用 wxwidget 库构建 c++

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

我一直在尝试在 Linux 中编译和 运行 一个带有 Wxwidget 的简单 C++ 程序,但是当我构建它时,这就是我尝试构建时得到的结果:

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).

这是我的 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"
            ]
        }
    ]
}

我正在使用 Kali Linux 并且我一直在尝试寻找构建 运行 wxwidgets 库的方法数周,但我仍然找不到任何好的答案。 感谢您提前提供帮助!

我认为在 Linux 上的 VS Code 中使用 wxWidgets 时,最简单的方法是使用 CMake。首先,您需要 CMake 和 CMake 工具扩展:

首先,在 VS Code 中打开您的项目:

然后打开命令托盘和select "CMake:Quick Start":

然后为将在 CMake 文件中使用的项目输入名称,并为项目类型输入 select 可执行文件。我在项目中使用了“cmakewx”。在您 select 可执行文件之后,将创建一个“CMakeLists.txt”文件和一个构建文件夹。

打开 CMakeLists.txt 文件。在文件的中间应该有一行看起来像:

add_executable(cmakewx main.cpp)

在我的例子中,“cmakewx”是我在上面输入的项目名称。在您的情况下,它将是您输入的名称。将其更改为

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

但将“cmakewx”替换为您为项目选择的名称。

最后,再次打开命令托盘,select“CMake:Configure”

现在项目已准备就绪。您可以将状态栏上的按钮用于各种项目任务。此区域: can be used to change the project's configuration (debug/release/etc). This area will build the project, and these buttons 将调试和 运行 项目。

这可能看起来有很多步骤,但当您熟悉该过程后,只需大约 30 秒即可让项目准备就绪。


Intellisense 应该在您配置项目后开始工作。但我看到有时它不会。我不确定为什么。如果发生这种情况,关闭并重新打开项目应该可以使智能感知正常工作。