我剛開始使用Qt。編譯第一個示例時遇到問題。
main.cpp中:cmake的鏈接問題:未定義參考QPushButton
#include <QCoreApplication>
#include <QPushButton>
int main(int argc, char** argv)
{
QCoreApplication app(argc, argv);
QPushButton button ("Hello world !");
return app.exec();
}
CMake.txt:
cmake_minimum_required(VERSION 2.6)
project(new)
find_package(Qt4 REQUIRED)
enable_testing()
include_directories(${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR})
set(source_SRCS main.cpp)
qt4_automoc(${source_SRCS})
add_executable(new ${source_SRCS})
target_link_libraries(new${QT_QTCORE_LIBRARY})
add_subdirectory(tests)
install(TARGETS new RUNTIME DESTINATION .)
我得到在建築物的錯誤是:
undefined reference to `QPushButton::QPushButton(QString const&,QWidget*)'
它是連接問題,但我怎麼能解決它?
'target_link_libraries(新$ {} QT_QTCORE_LIBRARY)'應該是'target_link_libraries(新$ {} QT_LIBRARIES)' – drescherjm