I use qt official example and get error:
/media/roroco/disk750/Downloads/qtbase/examples/widgets/desktop/systray/main.cpp:50: undefined reference to `qInitResources_systray()'
here is my CMakeLists.txt
SET(CMAKE_PREFIX_PATH /media/roroco/disk750/Downloads/qtbase)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
find_package(Qt5Widgets)
add_executable(systray main.cpp window.cpp)
target_link_libraries(systray Qt5::Widgets)
How to make this example work
according error message undefined reference to `qInitResources_systray()', I should use following CMakeLists.txt
cmake_minimum_required(VERSION 3.3)
project(systray)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
SET(CMAKE_PREFIX_PATH /media/roroco/disk750/Downloads/qtbase)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
find_package(Qt5Widgets)
add_executable(systray main.cpp window.cpp systray.qrc)
target_link_libraries(systray Qt5::Widgets)
Related
I have a CMake project that works pretty good in Linux, but it doesn't under Windows.
The first issue comes by final linking:
[100%] Linking CXX shared library libProjlib.dll
CMakeFiles\Projlib.dir/objects.a(configserver.cpp.obj): In function `ConfigServer::findAdapter(unsigned long*)':
C:/Users/jose/Documents/git-Projects/Proj/Projlib/configserver.cpp:859: undefined reference to `GetIpAddrTable'
Error 1
findAdapter belongs to C:\Qt\Tools\mingw810_64\x86_64-w64-mingw32\include\iphlpapi.h, but doesn't link automatic
My project is missconfigured, I think. I would like to select the MinGW compiler, automatic through CMakeLists.txt (For now, I configure the compiler means cmake-gui.exe ..), and naturally fix the issue, but I don't know how. (Google didn't gave me a solution)
Please, any help or suggestion, link.. etc. will be wellcomed.
Here is my CMakeLists.txt
cmake_minimum_required(VERSION 3.13)
set(CMAKE_PROJECT_NAME "testProject")
project(${CMAKE_PROJECT_NAME})
set(CMAKE_BUILD_TYPE Debug)
if("Windows" STREQUAL "${CMAKE_SYSTEM_NAME}")
message(STATUS "_______________________________________Compiling on Windows")
elseif("Linux" STREQUAL "${CMAKE_SYSTEM_NAME}")
message(STATUS "_______________________________________Compiling on GNU/Linux :-)")
endif()
set(CMAKE_BUILD_PARALLEL_LEVEL 8)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
#list(APPEND CMAKE_PREFIX_PATH "/home/enigma/Qt/5.15.2/gcc_64") #linux
list(APPEND CMAKE_PREFIX_PATH "C:\\Qt\\Tools\\mingw810_64")
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
message(STATUS "___________________________________________________${CMAKE_BUILD_TYPE}")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(binPath "binDebugProj")
elseif()
set(binPath "binProj")
endif()
set(TMP_BUILD "tmpBuild")
set(Proj_LIB "Projlib")
add_subdirectory(${Proj_LIB} "${CMAKE_SOURCE_DIR}/../${binPath}/${TMP_BUILD}/${Proj_LIB}")
include_directories(${Proj_LIB})
The Solution is:
target_link_libraries(${CARDEA_LIB} PUBLIC Qt5::Core Qt5::Network iphlpapi)
At the end did work. (I was savin in anoter CMakeLists.txt AGGHH, too musch hours today)
I am a student writing a project. I have created a program (here's the link to SVN: https://mysvn.ru/Ilya_Antonov/antonov_sem_prj). I use CMake to build it and generate the .sln project. But when run it in Visual Studio, there are some errors: the compiler can't open the files "drumswindow.h" and "mainwindow.h" (fatal error C1083). Please, take a look at my CMakeLists.txt:
cmake_minimum_required(VERSION 3.1.0)
project(MusicSimulator VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
if(CMAKE_VERSION VERSION_LESS "3.7.0")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
endif()
find_package(Qt5 COMPONENTS Gui REQUIRED)
find_package(Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt5 COMPONENTS Core REQUIRED)
find_package(Qt5 COMPONENTS Multimedia REQUIRED)
add_executable(MusicSimulator
mainwindow.ui
mainwindow.cpp
mainwindow.h
main.cpp
drumswindow.ui
drumswindow.cpp
drumswindow.h
keyswindow.ui
keyswindow.cpp
keyswindow.h
images.qrc
drumres.qrc
keysres2.qrc
keysres3.qrc
keysres4.qrc
keysres5.qrc
keysres6.qrc
)
target_link_libraries(MusicSimulator Qt5::Widgets Qt5::Gui Qt5::Core Qt5::Multimedia)
What have I done wrong here?
You don't include the current source dir and therefore the compiler doesn't find it. Either add the current source dir or use the correct include statements (#include "keyswindow.h" for example)
My project works in debug version, but always crashes in release version, immediately after start. I am using clion and MINGW64 for windows. Even the following code crashes:
#include <iostream>
#include <QByteArray>
int main() {
QByteArray a("");
return 0;
}
cmake:
cmake_minimum_required(VERSION 3.12)
project(test)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_AUTOMOC ON)
set(SOURCE_FILES main.cpp)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(Qt5Core REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Gui REQUIRED)
include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS})
add_executable(test ${SOURCE_FILES})
target_link_libraries(test Qt5::Core Qt5::Widgets Qt5::Gui)
I'm learning CPP and this weekend I learn more about QT, I'm using CLion and Cmakelist. I try to compile a project but when I add the macro Q_OBJECT it's say me :
undefined reference to `vtable for DigitalClock'
I'm looking for solved my problm and add AUTOMOC but it still doesn't work.
Is my CMakelist correct ?
cmake_minimum_required(VERSION 3.7.2)
project(cpp_rush3)
find_package(Qt5Widgets REQUIRED)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -lncurses")
set(CMAKE_AUTOMOC_ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
include_directories(Qt/widgets)
set(SOURCE_FILES
ncurses/Curse.cpp
ncurses/Curse.hpp
ncurses/Panel.cpp
ncurses/Panel.hpp
Qt/window.cpp
Qt/window.hpp
main.cpp)
set(QT_SOURCE_FILES
Qt/main.cpp
Qt/widgets/cpu.cpp
Qt/widgets/cpu.hpp
Qt/widgets/monitor.cpp
Qt/widgets/monitor.hpp
Qt/widgets/date.cpp
Qt/widgets/date.hpp
Qt/window.cpp
Qt/window.hpp)
add_executable(cpp_rush3 ${SOURCE_FILES})
add_executable(qt_cpp_rush3 ${QT_SOURCE_FILES})
target_link_libraries(cpp_rush3 Qt5::Widgets)
target_link_libraries(qt_cpp_rush3 Qt5::Widgets)
I am trying to compile a program on QT creator with cmake. The code(its not my code, I am using it to test something) uses openMP. in my cmake file I have:
`enter code here`project(dbscan_try)
cmake_minimum_required(VERSION 2.8)
aux_source_directory(. SRC_LIST)
SET(CMAKE_CXX_FLAGS "{CMAKE_CXX_FLAGS} -std=c++11 -Wall -fPIC -pedantic -fopenmp -mtune=corei7-avx")
set(Boost_USE_STATIC_LIBS OFF) set(Boost_USE_MULTITHREADED ON) set(Boost_USE_STATIC_RUNTIME OFF) add_definitions(-DBOOST_UBLAS_NDEBUG) add_definitions("-std=c++11") add_definitions("-fopenmp")
add_definitions("-lgomp")
OPTION (USE_OpenMP "Use OpenMP" ON)
find_package(OpenMP)
if (OPENMP_FOUND)
message("OPENMP FOUND")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fopenmp")
find_package(PCL REQUIRED COMPONENTS) include_directories(${PCL_INCLUDE_DIRS} ) link_directories(${PCL_LIBRARY_DIRS}) add_definitions(${PCL_DEFINITIONS})
include_directories({/home/raman/Work/dbscan_try})
set(project_SOURCES
/home/raman/Work/cplusplus_projects/dbscan_try/main.cpp
/home/raman/Work/cplusplus_projects/dbscan_try/dbscan.cpp )
set(project_HEADERS
/home/raman/Work/cplusplus_projects/dbscan_try/dbscan.h)
set(OpenCV_INCLUDE_DIRS "${OpenCV_INSTALL_PATH}/include/opencv;${OpenCV_INSTALL_PATH}/include")
find_package(OpenCV 3.1.0 REQUIRED COMPONENTS) include_directories(-L/usr/local/lib -lopencv_core -lopencv_highgui -lopencv_imgcodecs -lopencv_saliency -lboost_system -lopencv_contrib) set( CMAKE_CXX_FLAGS "-g -Wall")
add_executable(${PROJECT_NAME} ${project_SOURCES})
target_link_libraries(dbscan_try ${PCL_LIBRARIES} ${OpenCV_LIBS} )
However, I am getting errors such as:
/home/raman/Work/cplusplus_projects/dbscan_try/dbscan.cpp:88: error: undefined reference to omp_set_num_threads'
/home/raman/Work/cplusplus_projects/dbscan_try/dbscan.cpp:89: error: undefined reference toGOMP_parallel_start'
etc.
I am new to C++ and cmake so I am not sure if I am doing somethign wrong here. I seem to have followed what other suggestions here mentioned and it worked for them.