c++ - 如何在 GCC 的 VSCode 中设置 wxWidgets?

标签 c++ gcc visual-studio-code wxwidgets

我正在尝试使用 wxWidgets 制作一个 GUI 项目。我不想使用 Visual Studio,而是想将 VSCode 与 GCC (MinGW) 结合使用。
我面临以下问题:我无法编译或运行任何包含 wxWidgets 库的代码。如何配置 c_cpp_properties.json 和 tasks.json 文件?

我已经完成了使用“Cygwin/MinGW 编译”部分“使用普通生成文件:”安装 wxWidgets 的说明。 ( https://docs.wxwidgets.org/3.1.2/plat_msw_install.html )
1. cd .../wxWidgets-3.1.2\build\msw
2. mingw32-make -f makefile.gcc(默认生成Build=debug)

并在我的文件中添加了以下内容:
tasks.json:

    "version": "2.0.0",
    "tasks": [
        {
            "label": "echo",
            "type": "shell",
            "command": "g++",
            "args": [
                "-g", "cApp.cpp", 
                "-I", "D:/Programme/wxWidgets-3.1.2/include/msvc", 
                "-I", "D:/Programme/wxWidgets-3.1.2/include", 
                "-L", "${WXWIN}/lib/vc_lib"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

c_cpp_properties.json:

    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "${WXWIN}/include/msvc",
                "${WXWIN}/include"
            ],
            "browse": { "limitSymbolsToIncludedHeaders": true,
                "path": [
                    "${WXWIN}/include/msvc",
                    "${WXWIN}/include"
                ]
            },
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE",
                "__WXMSW__",
                "NDEBUG",
                "WXUSINGDLL"
            ],
            "compilerPath": "E:/Programme/MinGW/bin/g++.exe",
            "compilerArgs": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}.exe",
                "-I", "${WXWIN}/include/msvc",
                "-I", "${WXWIN}/include",
                "-L", "${WXWIN}/gcc_lib",
                "-L", "${WXWIN}/gcc_lib/mswud"
            ]
        }
    ],
    "version": 4
} 

我在编译时从我自己的代码中得到了以下错误,它使用了#include "wx/wx.h":

                 from ${WXWIN}/include/wx/defs.h:45,
                 from ${WXWIN}/include/wx/wx.h:14,
                 from ${Project}\VSC-Basic-ProjectSetup\src\cMain.h:1,
                 from ${Project}\VSC-Basic-ProjectSetup\src\cMain.cpp:1:
${WXWIN}/include/msvc/wx/setup.h:12:6: error: #error "This file should only be included when 
     #error "This file should only be included when using Microsoft Visual C++"
      ^~~~~
...
...
...
In file included from ${WXWIN}/include/wx/platform.h:148:0,
                 from ${WXWIN}/include/wx/defs.h:45,
                 from ${WXWIN}/include/wx/wx.h:14,
                 from ${Project}\VSC-Basic-ProjectSetup\src\cMain.h:1,
                 from ${Project}\VSC-Basic-ProjectSetup\src\cMain.cpp:1:
${WXWIN}/include/msvc/wx/setup.h:125:27: fatal error: ../../../lib/vc_lib /msw /wx/setup.h: N
 #include wxSETUPH_PATH_STR
                           ^
compilation terminated.
The terminal process terminated with exit code: 1

${WXWIN}、${Project} 只是占位符。

最佳答案

我知道有点太晚了,但这是 VSCode 的“Hello World”项目。您可以观察所有必需的包含和库,以在 VSCode 中成功编译和链接您的项目。所有 3 个主要操作系统都包含在项目中。 https://github.com/huckor/wxwidgets-vscode

关于c++ - 如何在 GCC 的 VSCode 中设置 wxWidgets?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57912726/

相关文章:

python - pip 在 Mac OS X Mavericks (10.9) 上引发 stdio.h not found 错误

c++ - 带有 const ref initialise 的非常奇怪的输出

python - 如何在 vs 代码中激活虚拟环境?

c++ - Variadic 可转换检查类中的参数

c++ - list<string> test() 和 list<string> test 区别?

c++ - 为什么 C++ 单元测试因 die 程序而失败

python - Flake8 提示 "Undefined Variable"关于内置函数

c++ - 有没有办法避免隐式转换为 void*?

c - 想在 C 中创建一个写模式的文件

visual-studio-code - VS Code - 增加 5000 个分阶段 Git 更改的限制