Страницы

Поиск по вопросам

Показаны сообщения с ярлыком wxwidgets. Показать все сообщения
Показаны сообщения с ярлыком wxwidgets. Показать все сообщения

понедельник, 6 января 2020 г.

Как подружить wxWidgets и CLion (Windows + mingw-w64)?

#c #cmake #сборка #clion #wxwidgets


Хочу сделать GUI приложение и выбрал для этого Си (без ++) и wxWidgets. Скачал с
офф.сайта установщик, поставил (Установился в C:\wxWidgets-3.1.1, но я кинул рядом
с исходниками папку с библиотекой в папке wx есть файл, который просится в коде).

 

Думал, что на этом всё, но нет, при попытке компиляции вылазит ошибка, что нет библиотеки.

Ошибка:


  "C:\Program Files\JetBrains\CLion 2018.1.5\bin\cmake\bin\cmake.exe" --build C:\Users\Timoshka-WIN10\Documents\CLionProjects\GuiTEST\cmake-build-debug
--target GuiTEST -- -j 1
      [ 50%] Building C object CMakeFiles/GuiTEST.dir/main.c.obj
      C:\Users\Timoshka-WIN10\Documents\CLionProjects\GuiTEST\main.c:3:10: fatal
error: wx/wxprec.h: No such file or directory
       #include 
                ^~~~~~~~~~~~~
      compilation terminated.
      mingw32-make.exe[3]: * [CMakeFiles\GuiTEST.dir\build.make:62: CMakeFiles/GuiTEST.dir/main.c.obj]
Error 1
      mingw32-make.exe2:  [CMakeFiles\Makefile2:67: CMakeFiles/GuiTEST.dir/all] Error 2
      mingw32-make.exe1:  [CMakeFiles\Makefile2:79: CMakeFiles/GuiTEST.dir/rule] Error 2
      mingw32-make.exe: * [Makefile:117: GuiTEST] Error 2


CMakeLists.txt

cmake_minimum_required(VERSION 3.10)
project(GuiTEST C)

set(CMAKE_C_STANDARD 11)

add_executable(GuiTEST main.c)

target_include_directories ( GuiTEST PUBLIC
        $< BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}libs/wxWidgets-3.1.1/include >
        $< INSTALL_INTERFACE:libs/wxWidgets-3.1.1/include >  # /include/mylib
        )


Код с офф.сайта wxWidgets

// wxWidgets "Hello World" Program
// For compilers that support precompilation, includes "wx/wx.h".
#include 
#ifndef WX_PRECOMP
    #include 
#endif
class MyApp : public wxApp
{
public:
    virtual bool OnInit();
};
class MyFrame : public wxFrame
{
public:
    MyFrame();
private:
    void OnHello(wxCommandEvent& event);
    void OnExit(wxCommandEvent& event);
    void OnAbout(wxCommandEvent& event);
};
enum
{
    ID_Hello = 1
};
wxIMPLEMENT_APP(MyApp);
bool MyApp::OnInit()
{
    MyFrame *frame = new MyFrame();
    frame->Show(true);
    return true;
}
MyFrame::MyFrame()
    : wxFrame(NULL, 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!");
}


Говорят, что надо что-то подшаманить в CMakeLists.txt, или добавить target_include_directories,
но в первом случае вроде под Ubuntu и не понятно, а во втором и по официальному мануалу
для CMake тоже ничего не понятно :).
    


Ответы

Ответ 1



В CMake есть команда find_package. Поиск wxWidgets должен выглядеть так : cmake_minimum_required(VERSION 2.8) project(MySuperProgram) find_package(wxWidgets REQUIRED) add_executable(${PROJECT_NAME} "main.cpp") target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_17) target_link_libraries(${PROJECT_NAME} ${wxWidgets_LIBRARIES}) target_compile_definitions(${PROJECT_NAME} PRIVATE ${wxWidgets_DEFINITIONS}) target_include_directories(${PROJECT_NAME} PRIVATE ${wxWidgets_INCLUDE_DIRS}) У меня linux и этого вполне хватает чтобы скомпилировать проект Hello World. Я wxWidgets не использовал. Но по описаниям он написан на C++. Даже в вашем примере код C++. Не уверен что будет легко использовать wxWidgets с языком С.

Ответ 2



target_include_directories( GuiTEST PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/libs/wxWidgets-3.1.1/include

вторник, 5 февраля 2019 г.

Как подружить wxWidgets и CLion (Windows + mingw-w64)?

Хочу сделать GUI приложение и выбрал для этого Си (без ++) и wxWidgets. Скачал с офф.сайта установщик, поставил (Установился в C:\wxWidgets-3.1.1, но я кинул рядом с исходниками папку с библиотекой в папке wx есть файл, который просится в коде).

Думал, что на этом всё, но нет, при попытке компиляции вылазит ошибка, что нет библиотеки.
Ошибка:
"C:\Program Files\JetBrains\CLion 2018.1.5\bin\cmake\bin\cmake.exe" --build C:\Users\Timoshka-WIN10\Documents\CLionProjects\GuiTEST\cmake-build-debug --target GuiTEST -- -j 1 [ 50%] Building C object CMakeFiles/GuiTEST.dir/main.c.obj C:\Users\Timoshka-WIN10\Documents\CLionProjects\GuiTEST\main.c:3:10: fatal error: wx/wxprec.h: No such file or directory #include ^~~~~~~~~~~~~ compilation terminated. mingw32-make.exe[3]: * [CMakeFiles\GuiTEST.dir\build.make:62: CMakeFiles/GuiTEST.dir/main.c.obj] Error 1 mingw32-make.exe2: [CMakeFiles\Makefile2:67: CMakeFiles/GuiTEST.dir/all] Error 2 mingw32-make.exe1: [CMakeFiles\Makefile2:79: CMakeFiles/GuiTEST.dir/rule] Error 2 mingw32-make.exe: * [Makefile:117: GuiTEST] Error 2
CMakeLists.txt
cmake_minimum_required(VERSION 3.10) project(GuiTEST C)
set(CMAKE_C_STANDARD 11)
add_executable(GuiTEST main.c)
target_include_directories ( GuiTEST PUBLIC $< BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}libs/wxWidgets-3.1.1/include > $< INSTALL_INTERFACE:libs/wxWidgets-3.1.1/include > # /include/mylib )
Код с офф.сайта wxWidgets
// wxWidgets "Hello World" Program // For compilers that support precompilation, includes "wx/wx.h". #include #ifndef WX_PRECOMP #include #endif class MyApp : public wxApp { public: virtual bool OnInit(); }; class MyFrame : public wxFrame { public: MyFrame(); private: void OnHello(wxCommandEvent& event); void OnExit(wxCommandEvent& event); void OnAbout(wxCommandEvent& event); }; enum { ID_Hello = 1 }; wxIMPLEMENT_APP(MyApp); bool MyApp::OnInit() { MyFrame *frame = new MyFrame(); frame->Show(true); return true; } MyFrame::MyFrame() : wxFrame(NULL, 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!"); }
Говорят, что надо что-то подшаманить в CMakeLists.txt, или добавить target_include_directories, но в первом случае вроде под Ubuntu и не понятно, а во втором и по официальному мануалу для CMake тоже ничего не понятно :).


Ответ

target_include_directories( GuiTEST PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/libs/wxWidgets-3.1.1/include