[英]Building a wxWidgets project in VS Code
I try to start using Linux(Fedora 33) and now I've got a trouble.我尝试开始使用 Linux(Fedora 33),但现在遇到了麻烦。 I want to use VS Code and it builds simple cpp projects correctly, but I want to make GUI using wxWidgets.
我想使用 VS Code 并正确构建简单的 cpp 项目,但我想使用 wxWidgets 制作 GUI。 So I created simple example, but it doesn't want to build it.
所以我创建了简单的示例,但它不想构建它。 I installed wxWidgets from rpm package.
我从 rpm package 安装了 wxWidgets。 I also added pathes into includePath in configuration file.
我还在配置文件的 includePath 中添加了路径。 Now I want to show you the code and errors.
现在我想向您展示代码和错误。
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
int main() { return 0; }
tasks.json任务.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ сборка активного файла",
"command": "/usr/bin/g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "компилятор: /usr/bin/g++"
}
],
"version": "2.0.0"
}
launch.json发射.json
{
"version": "0.2.0",
"configurations": [
{
"name": "g++ - Сборка и отладка активного файла",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Включить автоматическое форматирование для gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++ сборка активного файла",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
c_cpp_properties.json c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include/**",
"/usr/lib64/wx/include/**"
],
"defines": [],
"compilerPath": "/usr/bin/clang++",
"cStandard": "c17",
"cppStandard": "c++14",
"intelliSenseMode": "linux-clang-x64",
"compilerArgs": []
}
],
"version": 4
}
Now, there are no errors given me by intellisence, I think.现在,我认为智能没有给我带来任何错误。
Compilers errors:编译器错误:
Запуск сборки…
/usr/bin/g++ -g /home/nikita/Workfiles/wxex/main.cpp -o /home/nikita/Workfiles/wxex/main
/home/nikita/Workfiles/wxex/main.cpp:1:10: фатальная ошибка: wx/wxprec.h: Нет такого файла или каталога
1 | #include <wx/wxprec.h>
| ^~~~~~~~~~~~~
компиляция прервана.
Сборка завершена с ошибками.
The terminal process failed to launch (exit code: -1).
Replace代替
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
with和
#include <wx/wx.h>
wxWidgets provides wx-config
script under Unix which must be used to obtain the options necessary for compiling and linking programs using the library. wxWidgets 在 Unix 下提供了
wx-config
脚本,该脚本必须用于获取使用该库编译和链接程序所需的选项。 Please run wx-config --cxxflags
to obtain the full flags you need to put in your c_cpp_properties.json
and also wx-config --libs
to get the linker flags that you will need to use to make the program link, and not just compile, successfully.请运行
wx-config --cxxflags
以获取您需要放入c_cpp_properties.json
的完整标志以及wx-config --libs
以获取 linker 标志,您将需要使用这些标志来制作程序链接,而不仅仅是编译,成功。
As the person who starts using Linux AND wants to learn new library id recommend followinh:作为开始使用 Linux 并想学习新库 id 的人推荐如下:
Now the last make
command will display everything you need to include and link against.现在最后一个
make
命令将显示您需要包含和链接的所有内容。 You will also have a samples code you can refer to when needed.您还将有一个示例代码,您可以在需要时参考。
If you don't want to build the library from source - try the following如果您不想从源代码构建库 - 请尝试以下操作
Use the output from the commands above in you IDE.在 IDE 中使用上述命令中的 output。
HTH. HTH。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.