HYPER MIKAN BOX
検索
最近の変更
メディアマネージャー
サイトマップ
文書の表示
以前のリビジョン
バックリンク
ログイン
トレース:
この文書は読取専用です。文書のソースを閲覧することは可能ですが、変更はできません。もし変更したい場合は管理者に連絡してください。
====== CMakeを使ったHello World ====== {{:wxwidgets:wxwidgets_logo_blocks.svg?150|wxWidgets Logo}} https://docs.wxwidgets.org/latest/overview_helloworld.html 作業ディレクトリ <cli> $ cd ~/code/wxwidgets $ mkdir hello-wxwidgets-cmake $ cd hello-wxwidgets-cmake </cli> __main.cpp__ <code cpp> //////////////////////////////////////////////////////////////// // https://docs.wxwidgets.org/latest/overview_helloworld.html //////////////////////////////////////////////////////////////// // 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!"); } </code> __CMakeLists.txt__ <code cmake> cmake_minimum_required(VERSION 3.5 FATAL_ERROR) project(hello-wxwidgets-cmake LANGUAGES CXX) # https://cmake.org/cmake/help/latest/module/FindwxWidgets.html find_package(wxWidgets REQUIRED) include(${wxWidgets_USE_FILE}) add_executable(hello-wxwidgets-cmake main.cpp) target_link_libraries(hello-wxwidgets-cmake ${wxWidgets_LIBRARIES}) </code> ビルドディレクトリ <cli> $ mkdir build $ cd build </cli> CMakeコンフィギュレーション <cli> $ cmake .. -- The CXX compiler identification is GNU 13.3.0 -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Found wxWidgets: -L/usr/lib/x86_64-linux-gnu;-pthread;;;-lwx_gtk3u_xrc-3.2;-lwx_gtk3u_html-3.2;-lwx_gtk3u_qa-3.2;-lwx_gtk3u_core-3.2;-lwx_baseu_xml-3.2;-lwx_baseu_net-3.2;-lwx_baseu-3.2 (found version "3.2.4") -- Configuring done (0.3s) -- Generating done (0.0s) -- Build files have been written to: /home/freemikan/code/wxwidgets/hello-wxwidgets-cmake/build </cli> ビルド <cli> $ make [ 50%] Building CXX object CMakeFiles/hello-wxwidgets-cmake.dir/main.cpp.o [100%] Linking CXX executable hello-wxwidgets-cmake [100%] Built target hello-wxwidgets-cmake </cli> ビルド結果の確認 <cli> $ ls -l 合計 180 -rw-rw-r-- 1 freemikan freemikan 13370 5月 23 08:32 CMakeCache.txt drwxrwxr-x 6 freemikan freemikan 4096 5月 23 08:32 CMakeFiles -rw-rw-r-- 1 freemikan freemikan 5472 5月 23 08:32 Makefile -rw-rw-r-- 1 freemikan freemikan 1680 5月 23 08:32 cmake_install.cmake -rwxrwxr-x 1 freemikan freemikan 151144 5月 23 08:32 hello-wxwidgets-cmake </cli> 実行 <cli> $ ./hello-wxwidgets-cmake </cli> {{ :wxwidgets:wxwidgets_hello.jpg |Hello wxWidgets}}
文書の先頭へ