我在这里有一个相当特殊的设置,我对CMake没有足够的了解,找出错误。在Ubuntu上使用CMake编译Qt5代码12.04
我在Ubuntu 12.04上。 我从apt-add-repository ppa:ubuntu-sdk-team/ppa
安装Qt5,从apt-add-repository ppa:kalakris/cmake
(https://launchpad.net/~kalakris/+archive/ubuntu/cmake)安装CMake 2.8.11.2。
下面是完整的,最小的测试用例:
[email protected]:~/projects/qtcmaketest$ ls
blubb.cpp CMakeLists.txt
[email protected]:~/projects/qtcmaketest$ cat CMakeLists.txt
cmake_minimum_required(VERSION 2.8.11)
project (qtcmaketest)
find_package (Qt5Widgets REQUIRED)
add_executable(qtcmaketest blubb.cpp)
target_link_libraries (qtcmaketest Qt5::Widgets)
[email protected]:~/projects/qtcmaketest$ cat blubb.cpp
#include <QWidget>
#include <QApplication>
int main (int argc, char * argv[])
{
QApplication app (argc, argv);
QWidget foo;
foo.show();
}
[email protected]:~/projects/qtcmaketest$ cmake . && make
-- The C compiler identification is GNU 4.8.1
-- The CXX compiler identification is GNU 4.8.1
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/daniel/projects/qtcmaketest
Scanning dependencies of target qtcmaketest
[100%] Building CXX object CMakeFiles/qtcmaketest.dir/blubb.cpp.o
/home/daniel/projects/qtcmaketest/blubb.cpp:1:19: fatal error: QWidget: No such file or directory
#include <QWidget>
^
compilation terminated.
make[2]: *** [CMakeFiles/qtcmaketest.dir/blubb.cpp.o] Error 1
make[1]: *** [CMakeFiles/qtcmaketest.dir/all] Error 2
make: *** [all] Error 2
为什么包括目录中缺少时find_package是成功的?
我用这个指南: http://qt-project.org/doc/qt-5/cmake-manual.html
我只注意到,继从章节中的指令时,“使用Qt 5 CMake的年纪比2.8.9”,汇编作品。我加了以下几行:
include_directories(${Qt5Widgets_INCLUDE_DIRS})
add_definitions(${Qt5Widgets_DEFINITIONS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
我知道,这应该没有这些线路的工作,因为它运行的Ubuntu 14.04盒(默认情况下包括适当的Qt和CMake的版本)。我不希望得到这个问题的解决方案,但我可能需要一些关于在哪里寻找问题的指针。
最小的测试用例很重要。它告诉我们问题是否在你的代码中。如果blubb.cpp包含QWidget,发布的CMakeLists.txt会发生什么? – steveire 2014-12-01 19:22:52
感谢您的反馈@steveire,增加了一个最小的测试案例和一些信息。 – 2014-12-02 04:34:02
尝试'make VERBOSE = 1'而不是'make'。这是什么版本的Qt 5? – steveire 2014-12-02 08:34:19