I am writing a sample "Hello World" code from the wxWidgets documentation. I had installed the wxwidgets from source with gtk configured. After that I had installed it system wide. Below were the CLI commands entered by me:
mkdir gtk-build
cd gtk-build
../configure –-with-gtk
make
sudo su
make install
ldconfig
exit
cd samples
make
The executables in the samples directory work fine for me. Also I see that a wx directory is created in usr/local/include where I see a "wx.h" file. But when I include it in my .cpp file and compile using g++, I get following error:
hello.cpp:1:9: fatal error: wx/wx.h: No such file or directory
1 | #include<wx/wx.h>
Do I need to link the wx folder while compiling in any way?
How to do that? Also if I want to use a CMakeList to build and compile the code, what arguments apart from add executable
will I need to run the basic "hello world" code using wxWidgets?
The code is used from official documentation as follows:
#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);
};
bool MyAPP::OnInit(){
MyFrame *frame = new MyFrame();
frame->Show();
return true;
}
enum{
ID_Hello = 1
};
MyFrame::MyFrame() : wxFrame(nullptr, wxID_ANY, "Hello World"){
wxMenu *menuFile = new wxMenu;
menuFile->Append(ID_Hello, "&Hello...\tCtrl-H", "Hello string is shown in status bar");
menuFile->AppendSeparator();
menuFile->Append(wxID_EXIT);
xwMenu *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 widgets");
Bind(wxEVT_MENU, &MyFrame::OnHello, this, ID_Hello);
Bind(wxEVT_MENU, &MyFrame::OnExit, this, wxID_EXIT);
Bind(wxEVT_MENU, &MyFrame::OnAbout, this, wxID_ABOUT);
}
void myFrame::OnExit(wxCommandEvent& event){
Close(true);
}
void myFrame::OnAbout(wxCommandEvent& event){
wxMessageBox("About Hello World!", wxOK | wxICON_INFORMATION);
}
void myFrame::OnHello(wxCommandEvent event){
wxLogMessage("Hello world from widgets");
}
I am compiling the code using CMakeList.txt
as follows:
cmake_minimum_required(VERSION 3.10)
project(Basic)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
add_executable(base hello.cpp)
target_include_directories(base PUBLIC "${PROJECT_BINARY_DIR}")
I am performing an out of source build using command cmake --build .
CMakeLists.txt
seems relevant. edit your question.find_package(wxWidgets ...
anywhere in your code.