[Experience sharing] deepin-IDE+CMake+wxWidgets开发环境搭建
Tofloor
poster avatar
北冥夜未央
deepin
Ecological co-builder
2023-12-14 05:31
Author

一、背景
1、Code::Blocks20.03版本不能用wxWidgets3.2直接构建程序了。
2、最近开始学习使用CMake,CMake搭配代码编辑器太好用了,从此可以摆脱各种臃肿的IDE了。
3、找遍全网,竟然没有一篇关于Linux下搭建代码编辑器+CMake+wxWidgets开发环境的,只能自己摸索。

二、编译wxWidgets
1、官网https://www.wxwidgets.org/下载最新稳定版wxWidgets3.2.4源码。
2、安装编译工具sudo apt install gcc g++ cmake make
3、安装依赖库
sudo apt install libgtk-3-dev libgl1-mesa-dev libglu1-mesa-dev libegl1-mesa-dev libgstreamer-plugins-base1.0-dev libcurl4-openssl-dev libwebkit2gtk-4.0-dev libpng-dev libjpeg-dev libtiff-dev
4、编译设置
静态库release版本:
../configure --prefix=/opt/wxWidgets/ --disable-shared --enable-unicode --enable-stl --with-opengl --disable-sys-libs --with-libpng --with-libjpeg --with-libtiff --with-expat --with-libcurl --enable-glcanvasegl --enable-mediactrl --enable-webview
动态库release版本:
../configure --prefix=/opt/wxWidgets/ --enable-unicode --enable-stl --with-opengl --disable-sys-libs --with-libpng --with-libjpeg --with-libtiff --with-expat --with-libcurl --enable-glcanvasegl --enable-mediactrl --enable-webview
注:设置了单独的目录就可以实现多个wxWidgets版本共存了。
5、开始编译 make && sudo make install
6、配置wxWidgets
sudo vim /etc/profile
在export PATH后添加:
PATH=$PATH:/opt/wxWidgets/bin
PATH=$PATH:/opt/wxWidgets/include
PATH=$PATH:/opt/wxWidgets/lib
执行source /etc/profile
sudo vim /etc/ld.so.conf.d/wxWidgets.conf输入以下内容:
/opt/wxWidgets
执行sudo ldconfig
注:最好是重启计算机

三、deepin-IDE构建工程
1、启动deepin-IDE,“新建文件或工程”→“新建工程”→“CMake”→“console”→输入工程名:wxdemo,设置工程位置→“创建”,配置Debug或Release。
2、main.cpp内容
#include "wx/wx.h"
class MyApp :public wxApp
{
public:
virtual bool OnInit();
};
class MyFrame :public wxFrame
{
public:
MyFrame(const wxString& title);
void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
void OnSize(wxSizeEvent& event);
void OnButtonOK(wxCommandEvent& event);
private:
DECLARE_EVENT_TABLE()
};
DECLARE_APP(MyApp)
IMPLEMENT_APP(MyApp)
bool MyApp::OnInit()
{
MyFrame *frame = new MyFrame(wxT("Minimal wxWidgets App"));
frame->Show(true);
return true;
}
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
EVT_SIZE( MyFrame::OnSize)
EVT_BUTTON(wxID_OK, MyFrame::OnButtonOK)
END_EVENT_TABLE()
void MyFrame::OnAbout(wxCommandEvent& event)
{
wxString msg;
msg.Printf(wxT("Hello and welcome to %s"), wxVERSION_STRING);
wxMessageBox(msg, wxT("About Minimal"), wxOK| wxICON_INFORMATION, this);
}
void MyFrame::OnQuit(wxCommandEvent& event)
{
Close();
}
void MyFrame::OnSize(wxSizeEvent& event)
{
}
void MyFrame::OnButtonOK(wxCommandEvent& event)
{
wxMessageBox(wxT("OK button is pressed"), wxT(""), wxOK, this);
}
MyFrame::MyFrame(const wxString& title) :wxFrame(NULL, wxID_ANY, title)
{
wxMenu *fileMenu = new wxMenu;
wxMenu *helpMenu = new wxMenu;
helpMenu->Append(wxID_ABOUT, wxT("&About...\tF1"), wxT("Show about dialog"));
fileMenu->Append(wxID_EXIT, wxT("&Exit\tAlt-X"), wxT("Quit this program"));
wxMenuBar *menuBar = new wxMenuBar();
menuBar->Append(fileMenu, wxT("&File"));
menuBar->Append(helpMenu, wxT("&Help"));
SetMenuBar(menuBar);
CreateStatusBar(2);
SetStatusText(wxT("Welcome to wxWidgets!"));
wxButton * button = new wxButton(this, wxID_OK, wxT("OK"), wxPoint(50,50));
}
3、CMakeLists.txt内容
cmake_minimum_required(VERSION 3.22.1)
project(wxdemo VERSION 0.1.0)
find_package(wxWidgets REQUIRED COMPONENTS core base)
include(${wxWidgets_USE_FILE})
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(wxdemo ${wxWidgets_LIBRARIES})
4、按Ctrl+B编译,按Ctrl+F5运行。

截图_deepin-unioncode_20231213210037.jpg

四、其他
1、用Code::Blocks打开程序
打开编译的目录,发现有.cbp格式的工程文件,可以用Code::Blocks打开,编译没有问题,运行会报“You must select a host application to “run” a commands-only target...”错误。
解决方法:菜单Project→Properties...→Build targets,把Type修改为:GUI application。
2、使用VScode构建
安装cmake、cmake tools、C/C++三个插件。使用“cmake ..”和make编译。
3、使用Sublime Text构建
Sublime Text配置比VScode上麻烦些,不过网上有教程,如果需要我可以单独出一个帖子。

Reply Favorite View the author
All Replies
nexfia
deepin
2023-12-14 05:38
#1

like

Reply View the author
青稚
Moderator
2023-12-14 05:40
#2

好耶like

Reply View the author
Ziggy
deepin
2023-12-14 05:58
#3

ld.so相关的我都不敢动 scream

之前试过临时设置了下Qt后来编译全部默认给我识别成非系统版本了

Reply View the author
hanzn-zzx
deepin
2023-12-14 05:59
#4

like

Reply View the author
北冥夜未央
deepin
Ecological co-builder
2023-12-14 06:03
#5
Ziggy

ld.so相关的我都不敢动 scream

之前试过临时设置了下Qt后来编译全部默认给我识别成非系统版本了

我之前也一直不敢乱动,后面查了很多资料发现可以在/etc/ld.so.conf.d下单独创建.conf文件来设置,而且这么设置着用了几年了,没发现问题。

Reply View the author
Ziggy
deepin
2023-12-14 06:13
#6
北冥夜未央

我之前也一直不敢乱动,后面查了很多资料发现可以在/etc/ld.so.conf.d下单独创建.conf文件来设置,而且这么设置着用了几年了,没发现问题。

不知道大佬对我们编译的东西敢不敢兴趣呢tail

只提供编译文档(参数)也是很赞的😁

我一般直接就是编译完压缩成tar就放上去了,二次编译的人看下路径直接解压就好

https://github.com/deepin-community/sig-deepin-shared-libs

Reply View the author
北冥夜未央
deepin
Ecological co-builder
2023-12-14 06:22
#7
Ziggy

不知道大佬对我们编译的东西敢不敢兴趣呢tail

只提供编译文档(参数)也是很赞的😁

我一般直接就是编译完压缩成tar就放上去了,二次编译的人看下路径直接解压就好

https://github.com/deepin-community/sig-deepin-shared-libs

太高看我了,当不得大佬称呼😂就自学了一段时间C++,GUI编程这不才刚开始搭学习环境么😃

Reply View the author
魔法师
deepin
2023-12-14 19:12
#8
Reply View the author
Mozart
deepin
2023-12-14 19:42
#9

like

Reply View the author
把一切操作变成GUI
deepin
Backbone of ecological co-construction group
2024-08-08 03:44
#10

诶呀。。。这帖子格式。。。

Reply View the author