Итак, я пытался скомпилировать пример hello world, предоставляемый wxWidgets, но безуспешно. Я объясню, что я сделал шаг за шагом, до текущей точки, где я застрял.
Компиляция wxWidgets
- Прежде всего, мой предпочтительный компилятор - MinGw-w64, и Поскольку wxWidgets советуют создавать свою библиотеку из исходного кода (скачано с wxWidgets, загружено ), я решил сделать это с помощью CMake.
- Я создал каталог с именем
cmake
внутри директории root wxWidgets (в моем случае: C:\C++\wxWidgets-3.1.3
). Также я создал каталог bin
для хранения скомпилированных двоичных файлов. - Затем я перешел в каталог
cmake
и запустил следующую команду конфигурации CMake: $ cmake -G "MinGW Makefiles" .. -D "wxBUILD_SHARED=OFF" -D "wxBUILD_MONOLITHIC=OFF" -D "CMAKE_BUILD_TYPE=debug" -D "CMAKE_C_COMPILER=gcc.exe" -D "CMAKE_CXX_COMPILER=g++.exe"
затем я начал сборку с помощью следующей команды: $ cmake --build . --target all
Полученные файлы .a
( stati c файлы библиотеки ) были помещены в * 1030 Каталог *. - Я повторил шаг 3 с параметром
-D "CMAKE_BUILD_TYPE=release"
. - Сгенерированные каталоги
lib\gcc_x64_lib\mswu
и lib\gcc_x64_lib\mswud
в include
каталог для удобства (поскольку он содержит setup.h
заголовочный файл).
В результате мой каталог C:\C++\wxWidgets-3.1.3\bin
содержит следующие файлы:
libwxexpat.a libwxpngd.a libwxtiff.a wxbase31u_net.a wxmsw31u_adv.a wxmsw31u_media.a wxmsw31u_stc.a wxmsw31ud_core.a wxmsw31ud_qa.a wxmsw31ud_xrc.a
libwxexpatd.a libwxregexu.a libwxtiffd.a wxbase31u_xml.a wxmsw31u_aui.a wxmsw31u_propgrid.a wxmsw31u_webview.a wxmsw31ud_gl.a wxmsw31ud_ribbon.a wxrc.exe*
libwxjpeg.a libwxregexud.a libwxzlib.a wxbase31ud.a wxmsw31u_core.a wxmsw31u_qa.a wxmsw31u_xrc.a wxmsw31ud_html.a wxmsw31ud_richtext.a
libwxjpegd.a libwxscintilla.a libwxzlibd.a wxbase31ud_net.a wxmsw31u_gl.a wxmsw31u_ribbon.a wxmsw31ud_adv.a wxmsw31ud_media.a wxmsw31ud_stc.a
libwxpng.a libwxscintillad.a wxbase31u.a wxbase31ud_xml.a wxmsw31u_html.a wxmsw31u_richtext.a wxmsw31ud_aui.a wxmsw31ud_propgrid.a wxmsw31ud_webview.a
Создание проекта Hello World
Я создал простой проект wxWidgets hello world со следующей файловой структурой:
app
| build
| headers
| sources
| | main.cpp
| CMakeLists.txt
Содержимое main.cpp
:
// wxWidgets "Hello World" Program
// For compilers that support precompilation, includes "wx/wx.h".
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#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
:
cmake_minimum_required(VERSION 2.8)
project(hello_world)
if (MINGW)
add_compile_options(--static)
endif()
set(wx_libraries_path "C:\\C++\\wxWidgets-3.1.3\\bin")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
include_directories("C:\\C++\\wxWidgets-3.1.3\\include\\mswud")
find_library(libwxexpat NAMES libwxexpatd PATH ${wx_libraries_path})
find_library(libwxjpeg NAMES libwxjpegd PATH ${wx_libraries_path})
find_library(libwxpng NAMES libwxpngd PATH ${wx_libraries_path})
find_library(libwxregexu NAMES libwxregexud PATH ${wx_libraries_path})
find_library(libwxscintilla NAMES libwxscintillad PATH ${wx_libraries_path})
find_library(libwxtiff NAMES libwxtiffd PATH ${wx_libraries_path})
find_library(libwxzlib NAMES libwxzlibd PATH ${wx_libraries_path})
find_library(wxbase31u NAMES wxbase31ud PATH ${wx_libraries_path})
find_library(wxbase31u_xml NAMES wxbase31ud_net PATH ${wx_libraries_path})
find_library(wxbase31u_net NAMES wxbase31ud_xml PATH ${wx_libraries_path})
find_library(wxmsw31u_adv NAMES wxmsw31ud_adv PATH ${wx_libraries_path})
find_library(wxmsw31u_aui NAMES wxmsw31ud_aui PATH ${wx_libraries_path})
find_library(wxmsw31u_core NAMES wxmsw31ud_core PATH ${wx_libraries_path})
find_library(wxmsw31u_gl NAMES wxmsw31ud_gl PATH ${wx_libraries_path})
find_library(wxmsw31u_html NAMES wxmsw31ud_html PATH ${wx_libraries_path})
find_library(wxmsw31u_media NAMES wxmsw31ud_media PATH ${wx_libraries_path})
find_library(wxmsw31u_propgri NAMES wxmsw31ud_propgrid PATH ${wx_libraries_path})
find_library(wxmsw31u_qa NAMES wxmsw31ud_qa PATH ${wx_libraries_path})
find_library(wxmsw31u_ribbon NAMES wxmsw31ud_ribbon PATH ${wx_libraries_path})
find_library(wxmsw31u_richtex NAMES wxmsw31ud_richtext PATH ${wx_libraries_path})
find_library(wxmsw31u_stc NAMES wxmsw31ud_stc PATH ${wx_libraries_path})
find_library(wxmsw31u_webview NAMES wxmsw31ud_webview PATH ${wx_libraries_path})
find_library(wxmsw31u_xrc NAMES wxmsw31ud_xrc PATH ${wx_libraries_path})
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Release")
include_directories("C:\\C++\\wxWidgets-3.1.3\\include\\mswu")
find_library(libwxexpat NAMES libwxexpat PATH ${wx_libraries_path})
find_library(libwxjpeg NAMES libwxjpeg PATH ${wx_libraries_path})
find_library(libwxpng NAMES libwxpng PATH ${wx_libraries_path})
find_library(libwxregexu NAMES libwxregexu PATH ${wx_libraries_path})
find_library(libwxscintilla NAMES libwxscintilla PATH ${wx_libraries_path})
find_library(libwxtiff NAMES libwxtiff PATH ${wx_libraries_path})
find_library(libwxzlib NAMES libwxzlib PATH ${wx_libraries_path})
find_library(wxbase31u NAMES wxbase31u PATH ${wx_libraries_path})
find_library(wxbase31u_xml NAMES wxbase31u_xml PATH ${wx_libraries_path})
find_library(wxbase31u_net NAMES wxbase31u_net PATH ${wx_libraries_path})
find_library(wxmsw31u_adv NAMES wxmsw31u_adv PATH ${wx_libraries_path})
find_library(wxmsw31u_aui NAMES wxmsw31u_aui PATH ${wx_libraries_path})
find_library(wxmsw31u_core NAMES wxmsw31u_core PATH ${wx_libraries_path})
find_library(wxmsw31u_gl NAMES wxmsw31u_gl PATH ${wx_libraries_path})
find_library(wxmsw31u_html NAMES wxmsw31u_html PATH ${wx_libraries_path})
find_library(wxmsw31u_media NAMES wxmsw31u_media PATH ${wx_libraries_path})
find_library(wxmsw31u_propgri NAMES wxmsw31u_propgri PATH ${wx_libraries_path})
find_library(wxmsw31u_qa NAMES wxmsw31u_qa PATH ${wx_libraries_path})
find_library(wxmsw31u_ribbon NAMES wxmsw31u_ribbon PATH ${wx_libraries_path})
find_library(wxmsw31u_richtex NAMES wxmsw31u_richtex PATH ${wx_libraries_path})
find_library(wxmsw31u_stc NAMES wxmsw31u_stc PATH ${wx_libraries_path})
find_library(wxmsw31u_webview NAMES wxmsw31u_webview PATH ${wx_libraries_path})
find_library(wxmsw31u_xrc NAMES wxmsw31u_xrc PATH ${wx_libraries_path})
endif()
include_directories("C:\\C++\\wxWidgets-3.1.3\\include")
link_directories("C:\\C++\\wxWidgets-3.1.3\\bin")
add_executable(app sources/main.cpp)
message(STATUS "${libwxexpat}")
target_link_libraries(app PRIVATE
${libwxexpat}
${libwxjpeg}
${libwxpng}
${libwxregexu}
${libwxscintilla}
${libwxtiff}
${libwxzlib}
${wxbase31u}
${wxbase31u_xml}
${wxbase31u_net}
${wxmsw31u_adv}
${wxmsw31u_aui}
${wxmsw31u_core}
${wxmsw31u_gl}
${wxmsw31u_html}
${wxmsw31u_media}
${wxmsw31u_propgrid}
${wxmsw31u_qa}
${wxmsw31u_ribbon}
${wxmsw31u_richtext}
${wxmsw31u_stc}
${wxmsw31u_webview}
${wxmsw31u_xrc}
)
После того, как я создал проект Файлы, которые я выполнил по команде CMake для настройки проекта:
cmake -G "MinGW Makefiles" .. -D "CMAKE_C_COMPILER=gcc.exe" -D "CMAKE_CXX_COMPILER=g++.exe" -D "CMAKE_BUILD_TYPE=Debug" -D "CMAKE_VERBOSE_MAKEFILE:BOOL=ON"
Затем я попытался и не смог построить проект с помощью следующей команды CMake:
cmake --build .
Ошибки компиляции
К сожалению, программа не удается скомпилировать, вот вывод:
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_progress_start C:\Users\Oiltanker\Git\Pepega-Inject\installer\build\CMakeFiles C:\Users\Oiltanker\Git\Pepega-Inject\installer\build\CMakeFiles\progress.marks
C:/C++/MingGW-w64/mingw64/bin/mingw32-make.exe -f CMakeFiles\Makefile2 all
mingw32-make.exe[1]: Entering directory 'C:/Users/Oiltanker/Git/Pepega-Inject/installer/build'
C:/C++/MingGW-w64/mingw64/bin/mingw32-make.exe -f CMakeFiles\app.dir\build.make CMakeFiles/app.dir/depend
mingw32-make.exe[2]: Entering directory 'C:/Users/Oiltanker/Git/Pepega-Inject/installer/build'
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\Users\Oiltanker\Git\Pepega-Inject\installer C:\Users\Oiltanker\Git\Pepega-Inject\installer C:\Users\Oiltanker\Git\Pepega-Inject\installer\build C:\Users\Oiltanker\Git\Pepega-Inject\installer\build C:\Users\Oiltanker\Git\Pepega-Inject\installer\build\CMakeFiles\app.dir\DependInfo.cmake --color=
Dependee "C:\Users\Oiltanker\Git\Pepega-Inject\installer\build\CMakeFiles\app.dir\DependInfo.cmake" is newer than depender "C:/Users/Oiltanker/Git/Pepega-Inject/installer/build/CMakeFiles/app.dir/depend.internal".
Dependee "C:/Users/Oiltanker/Git/Pepega-Inject/installer/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "C:/Users/Oiltanker/Git/Pepega-Inject/installer/build/CMakeFiles/app.dir/depend.internal".
Scanning dependencies of target app
mingw32-make.exe[2]: Leaving directory 'C:/Users/Oiltanker/Git/Pepega-Inject/installer/build'
C:/C++/MingGW-w64/mingw64/bin/mingw32-make.exe -f CMakeFiles\app.dir\build.make CMakeFiles/app.dir/build
mingw32-make.exe[2]: Entering directory 'C:/Users/Oiltanker/Git/Pepega-Inject/installer/build'
[ 50%] Building CXX object CMakeFiles/app.dir/sources/main.cpp.obj
C:\C++\MingGW-w64\mingw64\bin\g++.exe @CMakeFiles/app.dir/includes_CXX.rsp -g --static -o CMakeFiles\app.dir\sources\main.cpp.obj -c C:\Users\Oiltanker\Git\Pepega-Inject\installer\sources\main.cpp
[100%] Linking CXX executable app.exe
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_link_script CMakeFiles\app.dir\link.txt --verbose=1
"C:\Program Files\CMake\bin\cmake.exe" -E remove -f CMakeFiles\app.dir/objects.a
C:\C++\MingGW-w64\mingw64\bin\ar.exe cr CMakeFiles\app.dir/objects.a @CMakeFiles\app.dir\objects1.rsp
C:\C++\MingGW-w64\mingw64\bin\g++.exe -g -Wl,--whole-archive CMakeFiles\app.dir/objects.a -Wl,--no-whole-archive -o app.exe -Wl,--out-implib,libapp.dll.a -Wl,--major-image-version,0,--minor-image-version,0 @CMakeFiles\app.dir\linklibs.rsp
C:/C++/wxWidgets-3.1.3/bin/wxbase31ud.a(dlmsw.cpp.obj): In function `GetFileVersion':
C:/C++/wxWidgets-3.1.3/src/msw/dlmsw.cpp:67: undefined reference to `GetFileVersionInfoSizeW'
.......
C:/C++/wxWidgets-3.1.3/src/common/geometry.cpp:350: undefined reference to `wxDataInputStream::Read32()'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[2]: *** [CMakeFiles\app.dir\build.make:110: app.exe] Error 1
mingw32-make.exe[2]: Leaving directory 'C:/Users/Oiltanker/Git/Pepega-Inject/installer/build'
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:78: CMakeFiles/app.dir/all] Error 2
mingw32-make.exe[1]: Leaving directory 'C:/Users/Oiltanker/Git/Pepega-Inject/installer/build'
mingw32-make.exe: *** [Makefile:86: all] Error 2```