QT - Cmakelist - CLion - vtable doesn't compile - c++

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)

Related

CMake, MinGW=Undefined Reference to GetIpAddrTable-> iphlpapi.h

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)

Qt5 cmake Windows Linker Error

I just wanted to start a new project which uses Qt in combination with CMake. I (hope I) followed the docs, but it seems as if the linker is not doing its work correctly:
CMakeFiles\QtTest.dir/objects.a(main.cpp.obj): In function `QString::QString(char const*)':
P:/Qt/5.9.1/msvc2015_64/include/QtCore/qstring.h:659: undefined reference to `__imp__ZN7QString16fromAscii_helperEPKci'
CMakeFiles\QtTest.dir/objects.a(main.cpp.obj): In function `QTypedArrayData<unsigned short>::deallocate(QArrayData*)':
P:/Qt/5.9.1/msvc2015_64/include/QtCore/qarraydata.h:237: undefined reference to `__imp__ZN10QArrayData10deallocateEPS_yy'
I'm using mingw-w64 (the x86_64 installation) with CLion and its bundled CMake and Qt 5.9.1. My CMakeLists.txt looks like this:
cmake_minimum_required(VERSION 3.8)
project(QtTest)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR})
set(CMAKE_VERBOSE_MAKEFILE ON)
# Qt
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(Qt5_NO_LINK_QTMAIN ON)
set(CMAKE_PREFIX_PATH P:/Qt/5.9.1/msvc2015_64/lib/cmake)
find_package(Qt5Core REQUIRED)
get_target_property(QtCore_location Qt5::Core LOCATION)
message("QtCore version ${Qt5Core_VERSION} is at ${QtCore_location}")
# QtTest executable
set(SOURCE_FILES main.cpp)
add_executable(QtTest ${SOURCE_FILES})
target_link_libraries(QtTest Qt5::Core)
When creating the build files it outputs (correctly) QtCore version 5.9.1 is at P:/Qt/5.9.1/msvc2015_64/bin/Qt5Core.dll
The main.cpp contains just a call to QString for testing purposes:
#include <QtCore/QString>
int main() {
QString string = QString("test");
}
Why does this happen?

C++ .exe with .dll not running outside of CLion

The program runs just fine when started from inside CLion although it is refusing to run by double clicking the .exe with this error being shown when I try to run it:
The procedure entry point _ZNKSt7__cxx1112basic_stringlcSt11char_traitslcESalcEE12find_last_ofEPKcyy could not be located in the dynamic link library C:\Users\steppers\projects\cyan\bin\libcyan_engine.dll.
It looks to me like an issue with a standard lib or something judging by the basic_string bit but I'm at a complete loss here now.
Here is my root CMakeLists.txt:
cmake_minimum_required(VERSION 3.6)
project(cyan_test)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
add_subdirectory(engine)
include_directories(engine/include)
set(SOURCE_FILES src/main.cpp)
add_executable(cyan_test ${SOURCE_FILES})
target_link_libraries(cyan_test cyan_engine)
And the engine subdirectory's:
cmake_minimum_required(VERSION 3.6)
project(cyan_engine)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
add_subdirectory(lib/glfw-3.2.1)
include_directories(lib/glfw-3.2.1/include)
add_definitions("-fPIC")
add_subdirectory(lib/g3log-1.2)
include_directories(lib/g3log-1.2/src)
include_directories(include)
set(SOURCE_FILES <src files here>)
add_library(cyan_engine SHARED ${SOURCE_FILES})
target_link_libraries(cyan_engine glfw g3logger)
find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR})
target_link_libraries(cyan_engine ${OPENGL_gl_LIBRARY})
Any help would be greatly appreciated.

Building wxWidgets 3.1.0 on CLion (Ubuntu)

I am currently trying to build wxWidgets-3.1.0 on a CLion 1.3 project. I use Ubuntu 16.04 (64 bit). Basically, I edited the CMakeLists.txt file like this:
cmake_minimum_required(VERSION 3.5)
project(WxProva)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules"
${CMAKE_MODULE_PATH})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(WxProva ${SOURCE_FILES})
find_package(wxWidgets)
include_directories(${wxWidgets_INCLUDE_DIRS})
target_link_libraries(WxProva ${wxWidgets_LIBRARIES})
The "External Libraries" section also shows me wxWidgets, but when it comes to write some lines on my main.cpp, everything related with the library seems to be unreachable by the compiler (it's all written in red, like an error). Anyway, if I try to compile, that's the result:
/home/federico/ClionProjects/WxProva/main.cpp:2:35: fatal error: wxWidgets-3.1.0/include: File o directory non esistente
compilation terminated.
Which is like "File or directory doesn't exists."
How can I fix this?
After some experiments here solution. You can just copy it and change some information and ready to build and run.
cmake_minimum_required(VERSION 3.7)
project(Your_Project_Name) //any name for your project
set(CMAKE_CXX_STANDARD 11)
set(wxWidgets_ROOT_DIR </usr/include/wx-3.0-unofficial>) // here I am giving where to search for wxwidgets library. it can be different for you
set(wxWidgets_CONFIGURATION mswu)
find_package(wxWidgets COMPONENTS core base REQUIRED)
include(${wxWidgets_USE_FILE})
set(SOURCE_FILES main.cpp)
add_executable(FirstC ${SOURCE_FILES})
target_link_libraries(FirstC ${wxWidgets_LIBRARIES})
For more Information read https://wiki.wxwidgets.org/CMake
Edit 1
Here you shouldn't even add some compile and link config (wx-config --cxxflags and wx-config --libs) as it is necessary in NetBeans
Here is example configuration for macOS 10.14.4 (Mojave) and CLion 2019.1
(/usr/local is folder where I installed wxWidgets)
cmake_minimum_required(VERSION 3.14)
project(wx1Test)
set(CMAKE_CXX_STANDARD 14)
set(wxWidgets_ROOT_DIR </usr/local/include/wx-3.1>)
set(wxWidgets_CONFIGURATION mswu)
find_package(wxWidgets COMPONENTS core base REQUIRED)
include(${wxWidgets_USE_FILE})
set(SOURCE_FILES main.cpp)
add_executable(wx1Test ${SOURCE_FILES})
target_link_libraries(wx1Test ${wxWidgets_LIBRARIES})

undefined reference to `qInitResources_systray()'

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)