Cmake (Clion) cant link QT5 UiTools - qt

I have a cmake file for various dummy Qt5 applications.
cmake_minimum_required(VERSION 3.15)
project(Qt_demo)
set(CMAKE_CXX_STANDARD 17)
# Tell cmake where Qt is located
set(Qt5_DIR "~/Code/Cpp/Qt/5.12.6/gcc_64/lib/cmake/Qt5")
#enable mocking compiler
set(CMAKE_AUTOMOC ON)
#enable ui compiler
set(CMAKE_AUTOUIC ON)
#enable resources
set(CMAKE_AUTORCC ON)
# Tell cmake to find the modules Qt5Core and Qt5widgets
find_package(Qt5 COMPONENTS Core Widgets UiTools REQUIRED)
get_target_property(QtUiTools_location Qt5::UiTools LOCATION)
message("${QtUiTools_location}")
add_executable(screenshot_demo screenshot/screenshot_main.cpp screenshot/screenshot.cpp)
# Link the library to the executable
target_link_libraries(screenshot_demo Qt5::Core Qt5::Widgets)
qt5_add_resources(RC_SRC "application/application.qrc")
add_executable(application_demo application/main.cpp application/mainwindow.cpp ${RC_SRC})
qt5_use_modules(application_demo Core Widgets)
qt5_add_resources(CALC_RC_SRC "calculator_builder/calculatorbuilder.qrc")
add_executable(calculator_builder_demo calculator_builder/main.cpp calculator_builder/calculatorbuilder.cpp ${CALC_RC_SRC})
target_link_libraries(calculator_builder_demo Qt5::UiTools Qt5::Core Qt5::Widgets )
Furthermore I added the Qt5 desinger as an external tool in clion as per setup
The first two projects compile and run just fine. However in the last project (calculator builder) I am trying to use UITools which is a Qt5 Addon. When I hit the compile button I get the following error:
[ 28%] Linking CXX executable calculator_builder_demo
/home/marc/Code/Cpp/Qt/5.12.6/gcc_64/lib/libQt5UiTools.a(properties.o): In function `QFormInternal::variantToDomProperty(QFormInternal::QAbstractFormBuilder*, QMetaObject const*, QString const&, QVariant const&)':
/home/qt/work/qt/qttools/src/designer/src/uitools/../lib/uilib/properties.cpp:594: undefined reference to `QString::arg(QLatin1String, int, QChar) const'
/home/marc/Code/Cpp/Qt/5.12.6/gcc_64/lib/libQt5UiTools.a(formbuilderextra.o): In function `QFormInternal::QFormBuilderExtra::readUi(QIODevice*)':
/home/qt/work/qt/qttools/src/designer/src/uitools/../lib/uilib/formbuilderextra.cpp:145: undefined reference to `QVersionNumber::fromString(QStringView, int*)'
/home/qt/work/qt/qttools/src/designer/src/uitools/../lib/uilib/formbuilderextra.cpp:150: undefined reference to `QString::arg(QStringView, int, QChar) const'
collect2: error: ld returned 1 exit status
CMakeFiles/calculator_builder_demo.dir/build.make:137: recipe for target 'calculator_builder_demo' failed
make[3]: *** [calculator_builder_demo] Error 1
CMakeFiles/Makefile2:82: recipe for target 'CMakeFiles/calculator_builder_demo.dir/all' failed
make[2]: *** [CMakeFiles/calculator_builder_demo.dir/all] Error 2
CMakeFiles/Makefile2:89: recipe for target 'CMakeFiles/calculator_builder_demo.dir/rule' failed
make[1]: *** [CMakeFiles/calculator_builder_demo.dir/rule] Error 2
Makefile:118: recipe for target 'calculator_builder_demo' failed
make: *** [calculator_builder_demo] Error 2
I am totally lost. Any help would be greatly appreciated

Related

An error occurred when the ASAP(Automated Slide Analysis Platform) software was running

With the enthusiastic help of SO netizens, I configured all the environments required for ASAP (Automated Slide Analysis Platform)
The necessary libraries including Boost, Openslide, Qt, etc. have been successfully linked, but the following error occurred
====================[ Build | ASAP | Debug ]====================================
"D:\_Jason\Clion\CLion 2021.2.2\bin\cmake\win\bin\cmake.exe" --build D:\_Jason\C++_hospital\orignal\CLion1.9\ASAP-1.9\cmake-build-debug --target ASAP -- -j 9
[ 25%] Automatic MOC and UIC for target ASAP
[ 25%] Built target ASAP_autogen
[ 50%] Linking CXX executable ASAP.exe
CMakeFiles\ASAP.dir/objects.a(main.cpp.obj): In function `main':
D:/_Jason/C++_hospital/orignal/CLion1.9/ASAP-1.9/ASAP/main.cpp:6: undefined reference to `__imp__ZN12QApplicationC1ERiPPci'
D:/_Jason/C++_hospital/orignal/CLion1.9/ASAP-1.9/ASAP/main.cpp:7: undefined reference to `__imp__ZN4ASAPC1EP7QWidget'
D:/_Jason/C++_hospital/orignal/CLion1.9/ASAP-1.9/ASAP/main.cpp:8: undefined reference to `__imp__ZN7QWidget4showEv'
D:/_Jason/C++_hospital/orignal/CLion1.9/ASAP-1.9/ASAP/main.cpp:10: undefined reference to `__imp__ZN12QApplication4execEv'
D:/_Jason/C++_hospital/orignal/CLion1.9/ASAP-1.9/ASAP/main.cpp:7: undefined reference to `__imp__ZN4ASAPD1Ev'
D:/_Jason/C++_hospital/orignal/CLion1.9/ASAP-1.9/ASAP/main.cpp:6: undefined reference to `__imp__ZN12QApplicationD1Ev'
D:/_Jason/C++_hospital/orignal/CLion1.9/ASAP-1.9/ASAP/main.cpp:7: undefined reference to `__imp__ZN4ASAPD1Ev'
D:/_Jason/C++_hospital/orignal/CLion1.9/ASAP-1.9/ASAP/main.cpp:6: undefined reference to `__imp__ZN12QApplicationD1Ev'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [CMakeFiles\ASAP.dir\build.make:111: ASAP.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:163: CMakeFiles/ASAP.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:170: CMakeFiles/ASAP.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:168: ASAP] Error 2
It can be seen from "__imp__ZN12QApplicationD1Ev" that this is a Qt problem. The solution they gave in other forums is to add the statement QT += gui widgets core to the .pro file under this project.However, there is no .pro file in the ASAP source code, so I tried to use the qmake -project command to generate the .pro file. It still doesn't work after adding QT += gui widgets core

QT6 compilation error in new CLion project

I try to use CLion to make QT project, I have QT6 install and I just want to run a basic "helloworld" (to be sure that my configuration is ok). But i got some issues, my CLion problems terminal is empty but when I try to run the code I got this error :
"D:\CLion 2021.1.1\bin\cmake\win\bin\cmake.exe" --build D:\Qt\6.0.2\mingw81_64\bin --target GameRegister -- -j 12
Scanning dependencies of target GameRegister_autogen
[ 20%] Automatic MOC and UIC for target GameRegister
[ 20%] Built target GameRegister_autogen
Scanning dependencies of target GameRegister
[ 40%] Building CXX object CMakeFiles/GameRegister.dir/GameRegister_autogen/mocs_compilation.cpp.obj
[ 60%] Building CXX object CMakeFiles/GameRegister.dir/main.cpp.obj
[ 80%] Building CXX object CMakeFiles/GameRegister.dir/gameregister.cpp.obj
[100%] Linking CXX executable GameRegister.exe
Error copying file "D:/Qt/6.0.2/mingw81_64/lib/cmake/../../bin/Qt6Cored.dll" to "D:/Qt/6.0.2/mingw81_64/bin".
mingw32-make.exe[3]: *** [CMakeFiles\GameRegister.dir\build.make:141: GameRegister.exe] Error 1
mingw32-make.exe[3]: *** Deleting file 'GameRegister.exe'
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:95: CMakeFiles/GameRegister.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:102: CMakeFiles/GameRegister.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:136: GameRegister] Error 2
To make my configuration I followed this guide
https://www.jetbrains.com/help/clion/qt-tutorial.html#issues-limits
and I also look in Qt documentation to make my CMakeLists.txt.
my CMakeLists.txt :
cmake_minimum_required(VERSION 3.19)
project(GameRegister)
#Cmake with 20cpp version
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
#QT version
set(QT_VERSION 6)
set(REQUIRED_LIBS Core)
set(REQUIRED_LIBS_QUALIFIED Qt6::Core)
add_executable(${PROJECT_NAME}
main.cpp gameregister.cpp
gameregister.h
gameregister.ui
)
#Path to cmake lib in QT
set(CMAKE_PREFIX_PATH "D:/Qt/6.0.2/mingw81_64/lib/cmake")
if (NOT CMAKE_PREFIX_PATH)
message(WARNING "CMAKE_PREFIX_PATH is not defined, you may need to set it "
"(-DCMAKE_PREFIX_PATH=\"path/to/Qt/lib/cmake\" or -DCMAKE_PREFIX_PATH=/usr/include/{host}/qt{version}/ on Ubuntu)")
endif ()
#Find necessary packages
find_package(Qt${QT_VERSION} COMPONENTS ${REQUIRED_LIBS} REQUIRED)
find_package(Qt${QT_VERSION} COMPONENTS Widgets REQUIRED)
#Target packages
target_link_libraries(${PROJECT_NAME} ${REQUIRED_LIBS_QUALIFIED})
target_link_libraries(${PROJECT_NAME} Qt6::Widgets)
#auto generated by CLion on creation
if (WIN32)
set(DEBUG_SUFFIX)
if (CMAKE_BUILD_TYPE MATCHES "Debug")
set(DEBUG_SUFFIX "d")
endif ()
set(QT_INSTALL_PATH "${CMAKE_PREFIX_PATH}")
if (NOT EXISTS "${QT_INSTALL_PATH}/bin")
set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..")
if (NOT EXISTS "${QT_INSTALL_PATH}/bin")
set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..")
endif ()
endif ()
if (EXISTS "${QT_INSTALL_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.dll")
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory
"$<TARGET_FILE_DIR:${PROJECT_NAME}>/plugins/platforms/")
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
"${QT_INSTALL_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.dll"
"$<TARGET_FILE_DIR:${PROJECT_NAME}>/plugins/platforms/")
endif ()
foreach (QT_LIB ${REQUIRED_LIBS})
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
"${QT_INSTALL_PATH}/bin/Qt${QT_VERSION}${QT_LIB}${DEBUG_SUFFIX}.dll"
"$<TARGET_FILE_DIR:${PROJECT_NAME}>")
endforeach (QT_LIB)
endif ()
and that's my Run/Debug config :
So I don't know why i got this error, maybe one of my path is incorrect or I need to edit the configuration of my run/debug ?

CMake & QT5 & Conan // CMAKE_AUTOUIC not generating ui header files

I've tried solution given in this thread: CMake & QT5 - QT5_WRAP_UI not generating ui header files but nothing changes.
Here is my first CMakeLists.txt (at the root of the project, which calls the second one)
cmake_minimum_required (VERSION 3.11.2)
project(babel)
include(${CMAKE_SOURCE_DIR}/build/conanbuildinfo.cmake)
conan_basic_setup()
subdirs(client)
and the second one is:
include_directories(${babel_SOURCE_DIR}/client/inc)
include_directories(${babel_SOURCE_DIR}/common)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR})
set(babel_client_SRCS
main.cpp
mainwindow.cpp
)
set(CMAKE_CXX_FLAGS "-Wall -fPIC -std=c++11")
set(CMAKE_AUTOUIC ON)
set(AUTOGEN_BUILD_DIR ${CMAKE_SOURCE_DIR/client/inc})
add_executable(babel_client ${babel_client_SRCS})
target_link_libraries(babel_client ${CONAN_LIBS})
my main.cpp got #include "ui_mainwindow.h"
and here is the error output:
[ 33%] Building CXX object client/src/CMakeFiles/babel_client.dir/main.cpp.o
/plopPath/client/src/main.cpp:1:10: fatal error: ui_mainwindow.h: No such file or directory
#include "ui_mainwindow.h"
^~~~~~~~~~~~~~~~~
compilation terminated.
gmake[2]: *** [client/src/CMakeFiles/babel_client.dir/build.make:63: client/src/CMakeFiles/babel_client.dir/main.cpp.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:104: client/src/CMakeFiles/babel_client.dir/all] Error 2
gmake: *** [Makefile:84: all] Error 2
Any Ideas? I've tried putting the set(CMAKE_AUTOUIC ON) at different places in my CMaleLists.txt but it looks like nothing changes (there is NO ui_mainwindow.h created in the project folders)
PS: I'm using the multiplatform binary manager CONAN to get Qt (using Qt without .ui files is working perfectly fine however)
As shown in the documentation http://doc.qt.io/qt-5/cmake-manual.html, you have to add the mainwindow.ui file to babel_client_SRCS so that it is then passed to add_executable

C/C++ undefined reference for sqlite3's functions using CLion with CMAKE

CMAKE's file has this code:
cmake_minimum_required(VERSION 3.6)
project(HelloSqliteC)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.c)
add_executable(HelloSqliteC ${SOURCE_FILES})
The file main.c has this code:
#include <stdio.h>
#include <stdlib.h>
#include <sqlite3.h>
int main() {
sqlite3 *db;
int rc;
rc = sqlite3_open("database.db", &db);
if (rc) {
fprintf(stderr, "Can't open database: %s!\n", sqlite3_errmsg(db));
} else {
fprintf(stderr, "Opened database successfully!\n");
}
sqlite3_close(db);
return 0;
}
When I've trying compiling:
/home/marcus/ide/clion/clion-2016.3.1/bin/cmake/bin/cmake --build /home/marcus/projects/native/HelloSqliteC/cmake-build-debug --target HelloSqliteC -- -j 4
[ 50%] Building C object CMakeFiles/HelloSqliteC.dir/main.c.o
[100%] Linking C executable HelloSqliteC
CMakeFiles/HelloSqliteC.dir/main.c.o: In function `main':
/home/marcus/projects/native/HelloSqliteC/main.c:13: undefined reference to `sqlite3_open'
/home/marcus/projects/native/HelloSqliteC/main.c:16: undefined reference to `sqlite3_errmsg'
/home/marcus/projects/native/HelloSqliteC/main.c:21: undefined reference to `sqlite3_close'
collect2: error: ld returned 1 exit status
CMakeFiles/HelloSqliteC.dir/build.make:94: recipe for target 'HelloSqliteC' failed
make[3]: *** [HelloSqliteC] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/HelloSqliteC.dir/all' failed
make[2]: *** [CMakeFiles/HelloSqliteC.dir/all] Error 2
CMakeFiles/Makefile2:79: recipe for target 'CMakeFiles/HelloSqliteC.dir/rule' failed
make[1]: *** [CMakeFiles/HelloSqliteC.dir/rule] Error 2
Makefile:118: recipe for target 'HelloSqliteC' failed
make: *** [HelloSqliteC] Error 2
I tried solve this issue using different ways, but no success.
I'm using CLion C/C++, my OS is Ubuntu 16.04 and I install sqlite3 using autoconf.
For test, I used the main.c above and compiled in command line with "-l sqlite3" using GCC and I had success, but I want use CLion.
Help me, thanks.
I also use CLion C/C++. The OS is Ubuntu 18.04.
But I want to compile the main.cpp.
The CMakelist.txt is:
cmake_minimum_required(VERSION 3.13)
project(ProjectName)
set(CMAKE_CXX_STANDARD 14)
add_executable(student main.cpp)
target_link_libraries(ProjectName LINK_PUBLIC sqlite3)
It works successfully.
I solved this issue with this target_link_libraries(HelloSqlite3 LINK_PUBLIC sqlite3) or target_link_libraries(projectName LINK_PUBLIC libraryName).
CLion uses CMake for all the building and project configuration. You have to manually modify CMakeLists.txt. In fact this is a CMake question.
This line in your CMakeLists.txt will solve your problem:
add_compile_options(-l sqlite3)
But actually CMake has a more sophisticated dependency discovery system. Read How To Find Libraries to learn this.

How to build Quazip 0.5.1 on Windows 7?

I'm trying to build the quazip libary (version 0.5.1) on Windows 7 (32-bit) with Qt 5.0.1 32-Bit LGPL installed.
When i run in the Qt-Commandprompt:
qmake
mingw32-make
with the directory set to the folder in which I extracted Quazip (C:\Qt\quazip-0.5.1\quazip), I get the following error-log:
C:\Qt\quazip-0.5.1\quazip>mingw32-make
mingw32-make -f Makefile.Release
mingw32-make[1]: Entering directory 'C:/Qt/quazip-0.5.1/quazip'
g++ -Wl,-s -shared -mthreads -Wl,--out-implib,release\libquazip.a -o release\qua
zip.dll object_script.quazip.Release -LC:\Qt\Qt5\5.0.1\mingw47_32\lib -lQt5Core
./release\unzip.o:unzip.c:(.text+0x1008): undefined reference to `crc32'
./release\unzip.o:unzip.c:(.text+0x10aa): undefined reference to `inflate'
./release\unzip.o:unzip.c:(.text+0x10da): undefined reference to `crc32'
./release\unzip.o:unzip.c:(.text+0x1110): undefined reference to `crc32'
./release\unzip.o:unzip.c:(.text+0x1327): undefined reference to `inflateEnd'
./release\unzip.o:unzip.c:(.text+0x1727): undefined reference to `get_crc_table'
./release\unzip.o:unzip.c:(.text+0x186f): undefined reference to `inflateInit2_'
./release\zip.o:zip.c:(.text+0xac7): undefined reference to `crc32'
./release\zip.o:zip.c:(.text+0xb7c): undefined reference to `deflate'
./release\zip.o:zip.c:(.text+0xcdf): undefined reference to `deflate'
./release\zip.o:zip.c:(.text+0xef5): undefined reference to `deflateEnd'
./release\zip.o:zip.c:(.text+0x13a8): undefined reference to `get_crc_table'
./release\zip.o:zip.c:(.text+0x1af9): undefined reference to `deflateInit2_'
./release\quaadler32.o:quaadler32.cpp:(.text+0x2e): undefined reference to `adle
r32'
./release\quaadler32.o:quaadler32.cpp:(.text+0x61): undefined reference to `adle
r32'
./release\quaadler32.o:quaadler32.cpp:(.text+0xa1): undefined reference to `adle
r32'
./release\quaadler32.o:quaadler32.cpp:(.text+0xb1): undefined reference to `adle
r32'
c:/qt/qt5/tools/mingw/bin/../lib/gcc/i686-w64-mingw32/4.7.2/../../../../i686-w64
-mingw32/bin/ld.exe: ./release\quaadler32.o: bad reloc address 0x0 in section `.
rdata$_ZTI13QuaChecksum32[__ZTI13QuaChecksum32]'
collect2.exe: error: ld returned 1 exit status
Makefile.Release:106: recipe for target 'release\quazip.dll' failed
mingw32-make[1]: *** [release\quazip.dll] Error 1
mingw32-make[1]: Leaving directory 'C:/Qt/quazip-0.5.1/quazip'
makefile:34: recipe for target 'release' failed
mingw32-make: *** [release] Error 2
But in my Zlib-Folder (C:\Qt\Qt5\5.0.1\Src\qtbase\src\3rdparty\zlib) are all this listed files installed.
.
As I tried to solve the problem, I have added into the quazip.pro and into the quazip.pri:
INCLUDEPATH += $$[QT_INSTALL_PREFIX]/src/3rdparty/zlib
, how it is suggested here.
All other solutiuons I have found on Google so far aren't helping.
I hope someone of you can help me.
Greetings,
LVreg
The problem is that QuaZIP can not find the zlib library. You should include the path of the headers an also the libraries when you run qmake:
qmake "INCLUDEPATH+=C:/Qt/Qt5/5.0.1/Src/qtbase/src/3rdparty/zlib" "LIBS+=-LC:/Qt/Qt5/5.0.1/Src/qtbase/src/3rdparty/zlib -lz"
mingw32-make
There is a full explanation in my blog if you want to check it out: http://www.antonioborondo.com/2014/10/22/zipping-and-unzipping-files-with-qt/
Here is what worked for me (QuaZip 0.7 on Windows 7 compiled with MSVC13 32 bits):
In the command line type:
SET INCLUDE=<PathToZib\include>;%INCLUDE%
SET LIB=<PathToZib\lib>;%LIB%
qmake PREFIX=<FolderWhereInstallWillPutFiles> LIBS+=<PathToZib\lib>/zdll.lib
nmake
nmake install
everything between <> must be changed to your applicable path
NOTE:
in the LIBS+= part use / instead of \ as folders delimiter
try to make the lib of quazip on windows - look here:
https://www.maefloresta.com/wiki/doku.php?id=quazip_windows
but - try the following command - instead of "make" take "mingw32-make".

Resources