Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Building problem with cmake
Forum Updated to NodeBB v4.3 + New Features

Building problem with cmake

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 340 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Furret
    wrote on 13 Jan 2023, 09:13 last edited by
    #1

    Hi, everyone. I have a weird building problem.

    In my project, there is a sub project which is using std::thread and builds with cmake.
    The CMakeList.txt is like this:

    cmake_minimum_required(VERSION 3.2)
    project(integrated_calibtool)
    message(STATUS ${CMAKE_CXX_FLAGS})
    add_compile_options(-std=c++17 -pthread)
    
    find_package(jsoncpp REQUIRED)
    find_package(OpenCV REQUIRED)
    find_package(PCL 1.9 REQUIRED)
    find_package(Boost COMPONENTS thread system REQUIRED)
    
    set(THREADS_PREFER_PTHREAD_FLAG ON)
    find_package(Threads REQUIRED)
    include_directories(
      ${EIGEN3_INCLUDE_DIR}
      ${PCL_INCLUDE_DIRS}
      ${OpenCV_INCLUDE_DIR}
      ${Boost_INCLUDE_DIR}
    )
    
    link_directories(${PCL_LIBRARY_DIRS})
    add_definitions(${PCL_DEFINITIONS})
    
    add_executable(exe1 ~~~)
    target_link_libraries(exe1 ${OpenCV_LIBS})
    
    add_executable(exe2 ~~~)
    target_link_libraries(exe2 ${OpenCV_LIBS} jsoncpp pthread)
    
    add_executable(exe3 ~~~)
    target_link_libraries(exe3 ${OpenCV_LIBS})
    
    add_executable(exe4 ~~~)
    target_link_libraries(exe4 ${PCL_LIBRARIES})
    
    add_executable(exe5 ~~~)
    target_link_libraries(exe5 pthread)
    
    add_library(libname STATIC 
    	~~~
    )
    
    target_link_libraries(libname 
    	PUBLIC ${OpenCV_LIBS}
    	PUBLIC ${PCL_LIBRARIES}
    	PUBLIC Threads::Threads
    )
    

    And the parent qt project cmakelist is something like this:

    cmake_minimum_required(VERSION 3.5)
    
    project(SerialManager VERSION 0.1 LANGUAGES CXX)
    
    set(CMAKE_PREFIX_PATH /home/mtech/ExternalGitPackages/Qt/5.15.2/gcc_64)
    set(CMAKE_INCLUDE_CURRENT_DIR ON)
    
    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
    
    set(CMAKE_AUTOUIC ON)
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_AUTORCC ON)
    set(CMAKE_AUTOUIC_SEARCH_PATHS ~~~)
    
    set(CMAKE_CXX_STANDARD 17)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    set(THREADS_PREFER_PTHREAD_FLAG ON)
    
    find_package(OpenCV REQUIRED)
    find_package(Threads REQUIRED)
    
    find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
    find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
    find_package(Qt5Charts)
    
    
    
    set(PROJECT_SOURCES
            ~~~
    )
    
    add_subdirectory(subproject)
    
    add_executable(${PROJECT_NAME}
                ${PROJECT_SOURCES}
            )
    #target_include_directories(${PROJECT_NAME}
    #    PUBLIC integrated_calibration_tool
    #)
    
    #add_library(integrated_calibration_tool)
    include_directories(${CMAKE_SOURCE_DIR}/integrated_calibration_tool)
    
    target_link_libraries(${PROJECT_NAME}
        PUBLIC ${OpenCV_LIBS}
        PRIVATE Qt${QT_VERSION_MAJOR}::Widgets
        PRIVATE Qt${QT_VERSION_MAJOR}::Charts
        libmade
        PRIVATE Threads::Threads
    )
    
    set_target_properties(${PROJECT_NAME} PROPERTIES
        MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
        MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
        MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
        MACOSX_BUNDLE TRUE
        WIN32_EXECUTABLE TRUE
    )
    
    

    The problem is, I can completely build my qt project with cmake, but cannot with qtCreator.
    I made a folder "build" where

    build-Qtproject-Desktop_Qt_5_15_2_GCC_64bit-Debug and
    Qtproject

    both exists, and

    cd build
    cmake ../Qtproject
    make
    

    , no problem.

    On the otherside, Qt Creator keeps alerting me that
    /usr/include/c++/9/thread:126: error: undefined reference to `pthread_create'

    Actually, this error message pops up when I use cmake by explicitly telling the source and build location like this:

    mkdir build
    cmake -S Qtproject/ -B build/
    

    What is the thing that I'm missing??

    Thanks.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Axel Spoerl
      Moderators
      wrote on 13 Jan 2023, 10:41 last edited by
      #2

      Have a look at this.
      GCC-9 should work with the latest Qt 5.15-lts on Ubuntu 18.04 and 20.04.
      All other Linuxes on 5.15 prefer GCC-5, or GCC-10 and above.
      Qt 5.15.2, however, is not the latest LTS release.
      Isn't Qt 6 an option?

      Software Engineer
      The Qt Company, Oslo

      1 Reply Last reply
      0

      1/2

      13 Jan 2023, 09:13

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved