skip to Main Content

i can compile c++ file using visual studio, but i wanna compile it using Mingw(gcc / g++).

Note: i don’t know much about wxWidgets

when i run gcc main.cpp -I C:wxWidgets-3.2.5includemsvc -I C:wxWidgets-3.2.5include -L C:wxWidgets-3.2.5libvc_x64_lib -mwindows
it gives me this error message

In file included from C:wxWidgets-3.2.5include/wx/platform.h:159:0, from C:wxWidgets-3.2.5include/wx/defs.h:45, from C:wxWidgets-3.2.5include/wx/wx.h:14, from main.cpp:1: C:wxWidgets-3.2.5includemsvc/wx/setup.h:12:6: error: #error "This file should only be included when using Microsoft Visual C++" #error "This file should only be included when using Microsoft Visual C++" ^~~~~ In file included from C:wxWidgets-3.2.5include/wx/platform.h:159:0, from C:wxWidgets-3.2.5include/wx/defs.h:45, from C:wxWidgets-3.2.5include/wx/wx.h:14, from main.cpp:1: C:wxWidgets-3.2.5includemsvc/wx/setup.h:142:27: fatal error: ../../../lib/vc_lib/msw/wx/setup.h: No such file or directory #include wxSETUPH_PATH_STR ^ compilation terminated.

but i don’t want to use Microsoft Visual studio. i prefer to compile it using Mingw(g++ / gcc) or from a makefile

the code i tried to compile, it’s a simple hello world program that i got from internet.
it works perfectly with Microsoft Visual studio when i tried to compile.

#include <wx/wx.h>

class App : public wxApp {
public:
  bool OnInit() {
    wxFrame* window = new wxFrame(NULL, wxID_ANY, "GUI Test", wxDefaultPosition, wxSize(600, 400));
    wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
    wxStaticText* text = new wxStaticText(window, wxID_ANY, "Well Done!nEverything seems to be working",
      wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE_HORIZONTAL);
    text->SetFont(wxFont(20, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
    sizer->Add(text, 1, wxALIGN_CENTER);
    window->SetSizer(sizer);
    window->Show();
    return true;
  }
};

wxIMPLEMENT_APP(App);

2

Answers


  1. This is documented in the manual. Note that usually using some kind of build system (autoconf, CMake, …) is preferable to writing makefiles by hand, especially under Windows where wx-config is not available.

    As an aside, it would be interesting to know how did you arrive at the command line that you used, notably using clearly (or I would hope) MSVC-specific include path includemsvc with non-MSVC compiler.

    Login or Signup to reply.
  2. For convenience, you can download the precompiled binaries from wxWidgets’ official site. Note that you must download those for gcc for a specific version.
    If you want to use hand-write Makefiles, you need to use the following commands:

    g++ main.cpp -pipe -IC:wxWidgets-3.2.5include -IC:wxWidgets-3.2.5libgcc_dllmswu -LC:wxWidgets-3.2.5libgcc_dll -mwindows -lwxbase32u -lwxmsw32u_core
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search