Linux系统中,在Qt上使用CMake

1.更换源

新装的系统,默认的源下载速度太慢,更换为国内的镜像

在/etc/apt/sources.list文件前面添加如下条目

#添加阿里源
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

最后执行如下命令更新源

sudo apt-get update

2.安装G++与CMake工具

sudo apt-get install gcc g++
sudo apt-get install libqt4-dev
sudo apt-get install cmake

Qt选项中Kit配置

3.CMakeLists.txt编写

CMAKE_MINIMUM_REQUIRED(VERSION 3.0.0)

# 工程名称
PROJECT(helloworld)

# 头文件位置
INCLUDE_DIRECTORIES(
    ${CMAKE_CURRENT_SOURCE_DIR}/inc
)

# 文件设置
SET(test_src_files
    src/main.cpp

)

SET(test_inc_files
)

# 插件动态库生成
ADD_EXECUTABLE(
    ${PROJECT_NAME}
    ${test_src_files}
    ${test_inc_files}
)

TARGET_LINK_LIBRARIES(
    ${PROJECT_NAME}
)

CMake语法详解

猜你喜欢

转载自www.cnblogs.com/wjw1340/p/12743259.html