I have tried everything from wxWiki to chatGPT and nothing solves my issue, please note that I do not need an alternative solution, and want to understand what I am missing in this implementation.
Steps I followed,
-
Step 1: Install mingw64 on my windows 11 x64 processor using mingw-builds-binaries. I chose the Release of 13.2.0-rt_v11-rev1
x86_64-13.2.0-release-win32-seh-ucrt-rt_v11-rev1.7z
build. -
Step2: Create project folder
myWxProject
[%project%]
,%project%/libs/wxWidgets
[%wxWidgets%]
. -
Step 3: Download the wxWidgets source files from Windows 7z v3.235. Extract the files into
%wxWidgets%
. -
Step 4: Build the files using gcc make by going into
%wxWidgets%/build/msw/
and running the commandmingw32-make -f makefile.gcc BUILD=release SHARED=0 UNICODE=1
please note that even the next optionBUILD=debug
with the necessary changes to includes still gives the error. -
Step 5: Add VSCode configurations
c_cpp_properties.json
to%project%/.vscode/
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}\libs\wxWidgets\include",
"${workspaceFolder}\libs\wxWidgets\lib\gcc_lib\mswu"
],
"defines": [
"_DEBUG",
"UNICODE",
"__WXMSW"
],
"intelliSenseMode": "gcc-x64",
"compilerPath": "C:\mingw64\bin\g++.exe",
"cStandard": "c11",
"cppStandard": "c++17"
}
],
"version": 4
}
and tasks.json
to %project/.vscode/%
{
"version": "2.0.0",
"tasks": [
{
"label": "cpp-build-debug",
"type": "shell",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${workspaceFolder}\cpp-build-debug\${fileBasenameNoExtension}.exe",
"-I",
"${workspaceFolder}\libs/wxWidgets\include",
"${workspaceFolder}\libs/wxWidgets\lib\gcc_lib\mswu",
"-L",
"${workspaceFolder}\libs\wxWidgets\lib\gcc_lib",
"-lwxbase32u",
"-lwxmsw32u_core",
"-lwxmsw32u_adv"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$gcc"
]
}
]
}
- Step 6: Make a file
helloWorld.cpp
and have the simple wxWidgets example code in it.
// Start of wxWidgets "Hello World" Program
#include <wx/wx.h>
class MyApp : public wxApp
{
public:
bool OnInit() override;
};
wxIMPLEMENT_APP(MyApp);
class MyFrame : public wxFrame
{
public:
MyFrame();
private:
void OnHello(wxCommandEvent& event);
void OnExit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
};
enum
{
ID_Hello = 1
};
bool MyApp::OnInit()
{
MyFrame *frame = new MyFrame();
frame->Show(true);
return true;
}
MyFrame::MyFrame()
: wxFrame(nullptr, wxID_ANY, "Hello World")
{
wxMenu *menuFile = new wxMenu;
menuFile->Append(ID_Hello, "&Hello...tCtrl-H",
"Help string shown in status bar for this menu item");
menuFile->AppendSeparator();
menuFile->Append(wxID_EXIT);
wxMenu *menuHelp = new wxMenu;
menuHelp->Append(wxID_ABOUT);
wxMenuBar *menuBar = new wxMenuBar;
menuBar->Append(menuFile, "&File");
menuBar->Append(menuHelp, "&Help");
SetMenuBar( menuBar );
CreateStatusBar();
SetStatusText("Welcome to wxWidgets!");
Bind(wxEVT_MENU, &MyFrame::OnHello, this, ID_Hello);
Bind(wxEVT_MENU, &MyFrame::OnAbout, this, wxID_ABOUT);
Bind(wxEVT_MENU, &MyFrame::OnExit, this, wxID_EXIT);
}
void MyFrame::OnExit(wxCommandEvent& event)
{
Close(true);
}
void MyFrame::OnAbout(wxCommandEvent& event)
{
wxMessageBox("This is a wxWidgets Hello World example",
"About Hello World", wxOK | wxICON_INFORMATION);
}
void MyFrame::OnHello(wxCommandEvent& event)
{
wxLogMessage("Hello world from wxWidgets!");
}
- Step 7: Finally run the
cpp-build-debug
task.
Error
In file included from %project%libs/wxWidgetsinclude/wx/defs.h:45,
from %project%libs/wxWidgetsinclude/wx/wx.h:14,
from %project%helloWorld.cpp:2:
%project%libs/wxWidgetsinclude/wx/platform.h:159:10: fatal error: wx/setup.h: No such file or directory
159 | #include "wx/setup.h"
| ^~~~~~~~~~~~
compilation terminated.
The things I am sure of:
I can ensure that there is a file called setup.h in the directory %wxWidgets%/lib/gcc_lib/mswu/wx/
but even though the folder is in include it does not find it. Something bizzare I had noticed, the extraction of the sources had a folder inside include %wxWidgets%/include/msvc
which also contains a wx
folder and a setup.h
, if I understand it correct from this wiki this file is for the visual studio build setup, hence I will not be using it. I did try everything that came to my mind for the past couple of days and for the life of me could not figure out why it gives me this setup.h
error.
I hope this information is enough. I can provide the entire built folder with my project if you want for the exact files in my system, but since its quite large I did not include it right now.
[EDIT] Additional information:I have the same issue when compiling the minimal
program from the samples. This was once again built by gcc-make mingw32-make -f makefile.gcc
after navigating into the minimal sample folder.
2
Answers
Quite a lot of issues in the above code including not having -I for all my includes as mentioned by @Xaviou. I want to answer this question in such a way that someone could reproduce a wxWidgets development environment on VSCode.
Assuming this is your project folder structure and the build files are to be in
./build
.First of all we need to populate
c_cpp_properties.json
(needs theC/C++
extension by Microsoft to work). This step is to avoid one's itelli-sense not go nuts.The force include was necessary for me since one of the extension I installed took precedence over the files in the include directly.
Now VSCode intelli-sense would not complain if you include a header. For building a file, I switched to a make file as seen in the tree rather than VSCode tasks but the flags and the libraries will not change either way.
The order of library includes at least when compiled with
mingw-make
is really important. And from some page flips of the documentation this seems to be the order for most of the libs in wxWidgets, so use whichever library you want or just include everything if build time is not an issue for you.Hope this helps, people in the future :) I now switched to cmake and clion for my development since I know whats actually going on in the build process.
I can see 2 errors in your configurations files (not sure it will solve your problem, but who knows …):
shoud be:
And if you’re using the debug version of the libs, the include path is not:
but