差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン前のリビジョン
次のリビジョン
前のリビジョン
wxwidgets:helloworld-cmake [2025/05/23 08:36] freemikanwxwidgets:helloworld-cmake [2025/05/24 07:37] (現在) – [プログラムのソースコード] freemikan
行 1: 行 1:
 ====== CMakeを使ったHello World ====== ====== CMakeを使ったHello World ======
 +{{:wxwidgets:wxwidgets_logo_title.svg?350|wxWidgets Logo}}
  
-{{:wxwidgets:wxwidgets_logo_blocks.svg?150|wxWidgets Logo}} 
  
 +===== 前提 =====
 +[[install|インストールのページ]]に従い、wxWidget 3.2がインストール済みであることを前提とします。
 +また、CMakeもインストールされている必要があります。
  
-https://docs.wxwidgets.org/latest/overview_helloworld.html+===== 作業ディレクトリ ===== 
 +作業ディレクトリは $HOME/code/wxwidgets/hello-wxwidgets-cmake とします。
  
- +<note> 
-業ディレクトリ+繰り返しになりますが、こういった名前やパスは、何かしら決めておかないと説明がしづらいので提示しているだけです。 
 +同じ名前にする必要は全くありません。 
 +ご自身の好みの場所に好きな名前で成してください。 
 +</note>
  
 <cli> <cli>
-cd ~/code/wxwidgets +mkdir -p ~/code/wxwidgets/hello-wxwidgets-cmake 
-$ mkdir hello-wxwidgets-cmake +$ cd $_
-$ cd hello-wxwidgets-cmake+
 </cli> </cli>
  
-__main.cpp__ 
  
-<code cpp> +===== プログラムのソースコード ===== 
-// Start of wxWidgets "Hello World" Program +プログラムのソースコードは、[[wxwidgets:helloworld#プログラムのソースコード|前回のHello World]]で使用したものと全く同じです。 
-#include <wx/wx.h> +main.cppという名前でコピーを作成しておきます。 
-  +
-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 +
-}; +
-  +
-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 =====
 __CMakeLists.txt__ __CMakeLists.txt__
  
 <code cmake> <code cmake>
-cmake_minimum_required(VERSION 3.FATAL_ERROR)+cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
  
 project(hello-wxwidgets-cmake LANGUAGES CXX) project(hello-wxwidgets-cmake LANGUAGES CXX)
  
-# https://cmake.org/cmake/help/latest/module/FindwxWidgets.html +find_package(wxWidgets 3.2 REQUIRED)
-find_package(wxWidgets REQUIRED)+
 include(${wxWidgets_USE_FILE}) include(${wxWidgets_USE_FILE})
  
行 111: 行 43:
 </code> </code>
  
-ビルドディレクトリ+https://cmake.org/cmake/help/latest/module/FindwxWidgets.html
  
 +===== ビルドディレクトリの作成 =====
 <cli> <cli>
 $ mkdir build $ mkdir build
行 118: 行 51:
 </cli> </cli>
  
-CMakeコンフィギュレーション 
  
 +===== CMakeコンフィギュレーションの実行 =====
 <cli> <cli>
 $ cmake .. $ 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>
  
-ビルド 
  
 +===== ビルドの実行 =====
 <cli> <cli>
 $ make $ 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>
  
-ビルド結果の確認+あるいは 
 + 
 +<cli> 
 +$ cmake --build . 
 +</cli>
  
 +==== 結果の確認 ====
 <cli> <cli>
 $ ls -l $ ls -l
行 155: 行 80:
 </cli> </cli>
  
-実行 
  
 +===== Hello Worldプログラムの実行 =====
 <cli> <cli>
 $ ./hello-wxwidgets-cmake $ ./hello-wxwidgets-cmake
文書の先頭へ