ubuntu编译qt源码
时间: 2023-05-31 10:03:06 浏览: 178
以下是在Ubuntu系统下编译Qt源码的步骤:
1. 安装必要的依赖库:
```shell
sudo apt-get install build-essential libfontconfig1-dev libfreetype6-dev libx11-dev libxext-dev libxfixes-dev libxi-dev libxrender-dev libxcb1-dev libx11-xcb-dev libxcb-glx0-dev libxcb-keysyms1-dev libxcb-image0-dev libxcb-shm0-dev libxcb-icccm4-dev libxcb-sync0-dev libxcb-xfixes0-dev libxcb-shape0-dev libxcb-randr0-dev libxcb-render-util0-dev libxcb-xinerama0-dev libgl1-mesa-dev libglu1-mesa-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libicu-dev libssl-dev libsqlite3-dev libpq-dev libmysqlclient-dev libxml2-dev libxslt1-dev libopus-dev libvpx-dev libavcodec-dev libavformat-dev libswscale-dev libavutil-dev libavresample-dev libopus-dev libvpx-dev libxcb-xinerama0-dev libxcb-xinput0-dev
```
2. 下载Qt源码包并解压:
```shell
tar -xvf qt-everywhere-src-5.15.2.tar.xz
```
3. 进入解压后的目录并运行配置脚本:
```shell
cd qt-everywhere-src-5.15.2/
./configure -prefix /usr/local/qt5 -opensource -confirm-license -release -qt-zlib -qt-libpng -qt-libjpeg -qt-freetype -qt-harfbuzz -qt-pcre -qt-xcb -qt-xkbcommon -no-xcb-xlib -no-kms -no-opengl -no-xcb-glx -no-gbm -no-eglfs -no-directfb -no-linuxfb -no-kms -no-libinput -no-mtdev -no-evdev -no-xinput2 -no-xcb-xlib -no-xcb-xinput -no-xcb-xinerama -no-xcb-xkb
```
其中,`-prefix`指定Qt的安装路径,`-opensource`表示开源版本,`-confirm-license`表示接受许可协议,`-release`表示使用发布版本,`-qt-*`表示启用相应的模块,`-no-*`表示禁用相应的模块。
4. 编译:
```shell
make -j4
```
其中,`-j4`表示使用4个线程编译,可以根据自己的CPU核心数进行调整。
5. 安装:
```shell
sudo make install
```
安装完成后,即可在`/usr/local/qt5`目录下找到编译好的Qt库文件和头文件。
阅读全文