-1

Following some hello world with qt and cmake, this is my fold structure:

CMakeLists.txt
main.cpp
ui/mainwindow.ui
src/mainwindow.cpp
include/mainwindow.h

and this is CMakeList.txt:

cmake_minimum_required (VERSION 2.8)

# Project
set(PROJECTNAME "Hello")
project(${PROJECTNAME} C CXX)

set(${PROJECTNAME}_MAJOR_VERSION 0)
set(${PROJECTNAME}_MINOR_VERSION 1)

# qt
find_package(Qt4 REQUIRED)
set (QT_USE_QTMAIN TRUE)

include (${QT_USE_FILE})
add_definitions(${QT_DEFINITIONS})

# compilers
#set(CMAKE_CXX_FLAGS "-Wall -std=gnu++0x")

# files
include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(src)
include_directories(include)

set(${PROJECTNAME}_SOURCES
    main.cpp
    src/mainwindow.cpp
)

set(${PROJECTNAME}_HEADERS
    include/mainwindow.h
)

set(${PROJECTNAME}_HEADERS_MOC
    include/mainwindow.h
)

set(${PROJECTNAME}_FORMS
    ui/mainwindow.ui
)

QT4_WRAP_CPP(${PROJECTNAME}_HEADERS_MOC ${${PROJECTNAME}_HEADERS_MOC})
QT4_WRAP_UI(${PROJECTNAME}_FORMS_HEADERS ${${PROJECTNAME}_FORMS})
QT4_ADD_RESOURCES(${PROJECTNAME}_RESOURCES_RCC ${${PROJECTNAME}_RESOURCES})

# executables and installation
add_executable (
    ${${PROJECTNAME}_HEADERS}
    ${${PROJECTNAME}_SOURCES}
    ${${PROJECTNAME}_HEADERS_MOC}
    ${${PROJECTNAME}_FORMS_HEADERS}
)

target_link_libraries(${PROJECTNAME} ${QT_LIBRARIES})

tried different ways of add target_link_libraries but still get:

-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- 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
-- Looking for Q_WS_X11
-- Looking for Q_WS_X11 - found
-- Looking for Q_WS_WIN
-- Looking for Q_WS_WIN - not found.
-- Looking for Q_WS_QWS
-- Looking for Q_WS_QWS - not found.
-- Looking for Q_WS_MAC
-- Looking for Q_WS_MAC - not found.
-- Found Qt4: /usr/bin/qmake (found version "4.8.1")
CMake Error at CMakeLists.txt:61 (target_link_libraries):
  Cannot specify link libraries for target "Hello" which is not built by
  this project.


-- Configuring incomplete, errors occurred!

1 Answer 1

5

You are missing the target name as the first parameter to add_executable.

add_executable( 
  ${PROJECTNAME}     
  ${${PROJECTNAME}_HEADERS}
  ${${PROJECTNAME}_SOURCES}
  ${${PROJECTNAME}_HEADERS_MOC}
  ${${PROJECTNAME}_FORMS_HEADERS}
)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.