首页 > 解决方案 > 配置g++用wxwidget库构建c++

问题描述

我一直在尝试在 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,并且我一直在尝试寻找构建 run wxwidgets 库的方法数周,但我仍然找不到任何好的答案。感谢您提前提供帮助!

标签: c++linuxvisual-studio-codewxwidgets

解决方案


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

在此处输入图像描述

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

在此处输入图像描述

然后打开命令托盘并选择“CMake:Quick Start”:

在此处输入图像描述

然后输入将在 CMake 文件中使用的项目的名称,并为项目类型选择可执行文件。我在项目中使用了“cmakewx”。选择可执行文件后,将创建一个“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”替换为您为项目选择的名称。

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

在此处输入图像描述

现在该项目已准备就绪。您可以将状态栏上的按钮用于各种项目任务。此区域:在此处输入图像描述可用于更改项目的配置(调试/发布/等)。该区域在此处输入图像描述将构建项目,这些按钮在此处输入图像描述将调试和运行项目。

这可能看起来有很多步骤,但是当您熟悉该过程时,只需大约 30 秒即可准备好一个项目。


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


推荐阅读