如何使用 Mingw(gcc/g++) 或使用 makefile 来编译使用 wxWidgets 的 c++ 文件

问题描述 投票:0回答:1

我可以使用 Visual Studio 编译 C++ 文件,但我想使用 Mingw(gcc / g++) 编译它。

注意:我对wxWidgets了解不多

当我跑步时

gcc main.cpp -I C:\wxWidgets-3.2.5\include\msvc -I C:\wxWidgets-3.2.5\include -L C:\wxWidgets-3.2.5\lib\vc_x64_lib -mwindows
它给了我这个错误消息

In file included from C:\wxWidgets-3.2.5\include/wx/platform.h:159:0,                  from C:\wxWidgets-3.2.5\include/wx/defs.h:45,                  from C:\wxWidgets-3.2.5\include/wx/wx.h:14,                  from main.cpp:1: C:\wxWidgets-3.2.5\include\msvc/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.5\include/wx/platform.h:159:0,                  from C:\wxWidgets-3.2.5\include/wx/defs.h:45,                  from C:\wxWidgets-3.2.5\include/wx/wx.h:14,                  from main.cpp:1: C:\wxWidgets-3.2.5\include\msvc/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.

但我不想使用 Microsoft Visual studio。我更喜欢使用 Mingw(g++ / gcc) 或 makefile 来编译它

我尝试编译的代码,这是我从互联网上获得的一个简单的 hello world 程序。 当我尝试编译时,它与 Microsoft Visual studio 完美配合。

#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);
makefile g++ mingw wxwidgets
1个回答
0
投票

记录在手册中。请注意,通常使用某种构建系统(autoconf,CMake,...)比手动编写 makefile 更好,特别是在

wx-config
不可用的 Windows 下。

顺便说一句,了解您如何到达所使用的命令行,特别是使用非 MSVC 编译器明确(或我希望)MSVC 特定的包含路径

include\msvc
,将会很有趣。

© www.soinside.com 2019 - 2024. All rights reserved.