cmake文件

cmake_minimum_required(VERSION 3.10)
project(helloQt)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
list(APPEND CMAKE_PREFIX_PATH "/opt/Qt5.8.0/5.8/gcc_64")

find_package(Qt5Widgets REQUIRED)
find_package (Qt5Core REQUIRED )
find_package (Qt5Gui REQUIRED )

aux_source_directory(src DIR_SRCS)

add_executable(helloQt ${DIR_SRCS})

target_link_libraries(helloQt   Qt5::Widgets Qt5::Core Qt5::Gui)

设置CMAKE_PREFIX_PATH

find_package可能找不到qt库,这时可以设置CMAKE_PREFIX_PATH,保证cmake找得到qt

cmake -DCMAKE_PREFIX_PATH=/opt/Qt5.8.0/5.8/gcc_64 ..

注意

该路径需要包含bin和lib

ls -atlr /opt/Qt5.8.0/5.8/gcc_64
总用量 68K
drwxrwxr-x  2 root root 4.0K 9月  24  2019 bin
drwxrwxr-x  3 root root 4.0K 9月  24  2019 doc
drwxrwxr-x 81 root root 4.0K 9月  24  2019 include
drwxrwxr-x  4 root root  20K 9月  24  2019 lib
drwxrwxr-x  2 root root 4.0K 9月  24  2019 libexec
drwxrwxr-x 97 root root 4.0K 9月  24  2019 mkspecs
drwxrwxr-x  2 root root 4.0K 9月  24  2019 phrasebooks
drwxrwxr-x 25 root root 4.0K 9月  24  2019 plugins
drwxrwxr-x 25 root root 4.0K 9月  24  2019 qml
drwxrwxr-x  2 root root 4.0K 9月  24  2019 resources
drwxrwxr-x  3 root root  12K 9月  24  2019 translations

后来发现,只需要在CmakeLists.txt添加就可以啦

list(APPEND CMAKE_PREFIX_PATH "/opt/Qt5.8.0/5.8/gcc_64")

问题

构建报错 Failed to find “GL/gl.h” in “/usr/include/libdrm”

用cmake构建项目时报错,网上查询了一下发现时未安装opengl,于是安装便是了

sudo apt install mesa-common-dev

问题解决