我在這裏有一個相當特殊的設置,我對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