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 ?
Related
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
I’m trying to install and create the first Qt project. I am using CLion with CMake and Qt 6.
I set up CMake:
cmake_minimum_required(VERSION 3.17)
project(QSnake)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(QT_VERSION 6)
set(REQUIRED_LIBS Core Gui Widgets)
set(REQUIRED_LIBS_QUALIFIED Qt6::Core Qt6::Gui Qt6::Widgets)
set(CMAKE_PREFIX_PATH D:/Qt/6.0.2/mingw81_64/lib/cmake)
add_executable(${PROJECT_NAME} main.cpp)
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_package(Qt${QT_VERSION} COMPONENTS ${REQUIRED_LIBS} REQUIRED)
target_link_libraries(${PROJECT_NAME} ${REQUIRED_LIBS_QUALIFIED})
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()
Actually, this is how it was generated when the CLion project was created. I only set the path: D:/Qt/6.0.2/mingw81_64/lib/cmake
Just in case, I will also add the main.c code. It is also generated by CLion.
#include <QApplication>
#include <QPushButton>
int
main(int argc,
char *argv[])
{
QApplication a(argc, argv);
QPushButton button("Hello world!", nullptr);
button.resize(200, 100);
button.show();
return QApplication::exec();
}
I don’t see any problems with CMake, but when I try to run the project there is an error:
Error copying file "D:/Qt/6.0.2/mingw81_64/lib/cmake/../../bin/Qt6Cored.dll" to "D:/QSnake/cmake-build-debug".
mingw32-make[3]: *** [CMakeFiles\QSnake.dir\build.make:126: QSnake.exe] Error 1
mingw32-make[3]: *** Deleting file 'QSnake.exe'
mingw32-make[2]: *** [CMakeFiles\Makefile2:96: CMakeFiles/QSnake.dir/all] Error 2
mingw32-make[1]: *** [CMakeFiles\Makefile2:103: CMakeFiles/QSnake.dir/rule] Error 2
mingw32-make: *** [Makefile:137: QSnake] Error 2
What is this error and how do I fix it? I understand that there is no problem with build - only a copying error. And should copied dll be called "Cored" and not "Core"?
Thank you for your attention! If you need any additional information, please let me know - I will try to clarify the question.
Problem solved.
Whether it is useful to anyone, but the CMake automatically generated by CLion contains rows that cause an error in debug mode (adds 'd' suffix to all dll files):
if (CMAKE_BUILD_TYPE MATCHES "Debug")
set(DEBUG_SUFFIX "d")
endif()
Deleting those lines saved me :)
The real answer to this is that you are using a CMake profile defined as "debug", while you have not installed a debug version of Qt.
To solve, and not patch, if you don't want to download the debug DLLs, then create a CMake profile for "release".
I had the same problem and none of the answers here solved the problem.
Here is how I could solved it for myself:
TL;DR:
set prefix-path when creating project
copy missing Qt6Cored.dll into bin-folder
When creating the new project in Clion be sure to set the correct prefix-path:
You can see in your error message that /bin/Qt6Cored.dll gets added to the prefix path automatically, so you don't have to select the bin folder when setting the prefix-path.
After this I still got an error message (but path was displayed correctly without any "/../..").
I then realized that there was no Qt6Cored.dll in my bin-folder:
So I simply copied the missing file from C:\Qt\6.1.3\msvc2019_64\bin into C:\Qt\6.1.3\mingw81_64\bin
And then it worked!
If you don't have the msvc2019_64 folder you can install it by modifying Qt via app-settings:
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
I setup QT for windows using this tutorial - https://wiki.qt.io/MinGW-64-bit
I need to use CMAKE
I create empty project in qtcreator, but when i try cmake it i get this errors:
Starting to parse CMake project, using: "-DCMAKE_BUILD_TYPE:STRING=Debug", "-DCMAKE_CXX_COMPILER:STRING=C:/msys64/mingw64/bin/g++.exe", "-DCMAKE_CXX_COMPILER_TARGET :STRING=x86_64-pc-msys", "-DCMAKE_C_COMPILER:STRING=C:/msys64/mingw64/bin/gcc.exe", "-DCMAKE_C_COMPILER_TARGET:STRING=x86_64-pc-msys", "-DCMAKE_PREFIX_PATH:STRING=C:/msys64/mingw64", "-DCMAKE_SYSROOT:STRING=C:/msys64", "-DQT_QMAKE_EXECUTABLE:STRING=C:/msys64/mingw64/bin/qmake.exe".
The CXX compiler identification is GNU 9.2.0
Check for working CXX compiler: C:/msys64/mingw64/bin/g++.exe
Check for working CXX compiler: C:/msys64/mingw64/bin/g++.exe -- broken
CMake Error at C:/msys64/mingw64/share/cmake-3.15/Modules/CMakeTestCXXCompiler.cmake:53 (message):
The C++ compiler
"C:/msys64/mingw64/bin/g++.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/xxx/AppData/Local/Temp/QtCreator-RwlXKb/qtc-cmake-tQFVtoZK/CMakeFiles/CMakeTmp
Run Build Command(s):C:/msys64/usr/bin/ninja.exe cmTC_373cd && [1/2] Building CXX object CMakeFiles/cmTC_373cd.dir/testCXXCompiler.cxx.obj
FAILED: CMakeFiles/cmTC_373cd.dir/testCXXCompiler.cxx.obj
C:\msys64\mingw64\bin\g++.exe --sysroot=C:/msys64 -o CMakeFiles/cmTC_373cd.dir/testCXXCompiler.cxx.obj -c testCXXCompiler.cxx
/bin/sh: C:msys64mingw64bing++.exe: command not found
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:3 (project)
Configuring incomplete, errors occurred!
See also "C:/Users/xxx/AppData/Local/Temp/QtCreator-RwlXKb/qtc-cmake-tQFVtoZK/CMakeFiles/CMakeOutput.log".
See also "C:/Users/xxx/AppData/Local/Temp/QtCreator-RwlXKb/qtc-cmake-tQFVtoZK/CMakeFiles/CMakeError.log".
CMake Deprecation Warning:
The 'cmake-server(7)' is deprecated. Please port clients to use the
'cmake-file-api(7)' instead.
CMake Project parsing failed.
It seems error in this string:
C:msys64mingw64bing++.exe
It because slashes not handled correctly.
So how i fix it? Where there setings stored?
UPDATE 1
Here is my CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(t2 LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt5 COMPONENTS Core Quick REQUIRED)
if(ANDROID)
add_library(t2 SHARED main.cpp qml.qrc)
else()
add_executable(t2 main.cpp qml.qrc)
endif()
target_compile_definitions(t2
PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
target_link_libraries(t2
PRIVATE Qt5::Core Qt5::Quick)
# QtCreator supports the following variables for Android, which are identical to qmake Android variables.
# Check http://doc.qt.io/qt-5/deployment-android.html for more information.
# These variables must use CACHE, otherwise QtCreator won't see them.
#if(ANDROID)
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android" CACHE INTERNAL "")
# if (ANDROID_ABI STREQUAL "armeabi-v7a")
# set(ANDROID_EXTRA_LIBS ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so CACHE INTERNAL "")
# endif()
#endif()
I try and launch cmake CMakeLists.txt and it crete makefile
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.15
# Default target executed when no arguments are given to make.
default_target: all
.PHONY : default_target
# Allow only one "make -f Makefile2" at a time, but pass parallelism.
.NOTPARALLEL:
#=============================================================================
# Special targets provided by cmake.
# Disable implicit rules so canonical targets will work.
.SUFFIXES:
# Remove some rules from gmake that .SUFFIXES does not remove.
SUFFIXES =
.SUFFIXES: .hpux_make_needs_suffix_list
# Suppress display of executed commands.
$(VERBOSE).SILENT:
# A target that is always out of date.
cmake_force:
.PHONY : cmake_force
#=============================================================================
# Set environment variables for the build.
# The shell in which to execute make rules.
SHELL = /bin/sh
# The CMake executable.
CMAKE_COMMAND = /usr/bin/cmake.exe
# The command to remove a file.
RM = /usr/bin/cmake.exe -E remove -f
# Escaping for special characters.
EQUALS = =
# The top-level source directory on which CMake was run.
CMAKE_SOURCE_DIR = /c/projects/t2
# The top-level build directory on which CMake was run.
CMAKE_BINARY_DIR = /c/projects/t2
#=============================================================================
# Targets provided globally by CMake.
# Special rule for the target rebuild_cache
rebuild_cache:
#$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
/usr/bin/cmake.exe -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : rebuild_cache
# Special rule for the target rebuild_cache
rebuild_cache/fast: rebuild_cache
.PHONY : rebuild_cache/fast
# Special rule for the target edit_cache
edit_cache:
#$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..."
/usr/bin/ccmake.exe -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : edit_cache
# Special rule for the target edit_cache
edit_cache/fast: edit_cache
.PHONY : edit_cache/fast
# The main all target
all: cmake_check_build_system
$(CMAKE_COMMAND) -E cmake_progress_start /c/projects/t2/CMakeFiles /c/projects/t2/CMakeFiles/progress.marks
$(MAKE) -f CMakeFiles/Makefile2 all
$(CMAKE_COMMAND) -E cmake_progress_start /c/projects/t2/CMakeFiles 0
.PHONY : all
# The main clean target
clean:
$(MAKE) -f CMakeFiles/Makefile2 clean
.PHONY : clean
# The main clean target
clean/fast: clean
.PHONY : clean/fast
# Prepare targets for installation.
preinstall: all
$(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall
# Prepare targets for installation.
preinstall/fast:
$(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall/fast
# clear depends
depend:
$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
.PHONY : depend
#=============================================================================
# Target rules for targets named t2
# Build rule for target.
t2: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 t2
.PHONY : t2
# fast build rule for target.
t2/fast:
$(MAKE) -f CMakeFiles/t2.dir/build.make CMakeFiles/t2.dir/build
.PHONY : t2/fast
#=============================================================================
# Target rules for targets named t2_autogen
# Build rule for target.
t2_autogen: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 t2_autogen
.PHONY : t2_autogen
# fast build rule for target.
t2_autogen/fast:
$(MAKE) -f CMakeFiles/t2_autogen.dir/build.make CMakeFiles/t2_autogen.dir/build
.PHONY : t2_autogen/fast
main.o: main.cpp.o
.PHONY : main.o
# target to build an object file
main.cpp.o:
$(MAKE) -f CMakeFiles/t2.dir/build.make CMakeFiles/t2.dir/main.cpp.o
.PHONY : main.cpp.o
main.i: main.cpp.i
.PHONY : main.i
# target to preprocess a source file
main.cpp.i:
$(MAKE) -f CMakeFiles/t2.dir/build.make CMakeFiles/t2.dir/main.cpp.i
.PHONY : main.cpp.i
main.s: main.cpp.s
.PHONY : main.s
# target to generate assembly for a file
main.cpp.s:
$(MAKE) -f CMakeFiles/t2.dir/build.make CMakeFiles/t2.dir/main.cpp.s
.PHONY : main.cpp.s
t2_autogen/EWIEGA46WW/qrc_qml.o: t2_autogen/EWIEGA46WW/qrc_qml.cpp.o
.PHONY : t2_autogen/EWIEGA46WW/qrc_qml.o
# target to build an object file
t2_autogen/EWIEGA46WW/qrc_qml.cpp.o:
$(MAKE) -f CMakeFiles/t2.dir/build.make CMakeFiles/t2.dir/t2_autogen/EWIEGA46WW/qrc_qml.cpp.o
.PHONY : t2_autogen/EWIEGA46WW/qrc_qml.cpp.o
t2_autogen/EWIEGA46WW/qrc_qml.i: t2_autogen/EWIEGA46WW/qrc_qml.cpp.i
.PHONY : t2_autogen/EWIEGA46WW/qrc_qml.i
# target to preprocess a source file
t2_autogen/EWIEGA46WW/qrc_qml.cpp.i:
$(MAKE) -f CMakeFiles/t2.dir/build.make CMakeFiles/t2.dir/t2_autogen/EWIEGA46WW/qrc_qml.cpp.i
.PHONY : t2_autogen/EWIEGA46WW/qrc_qml.cpp.i
t2_autogen/EWIEGA46WW/qrc_qml.s: t2_autogen/EWIEGA46WW/qrc_qml.cpp.s
.PHONY : t2_autogen/EWIEGA46WW/qrc_qml.s
# target to generate assembly for a file
t2_autogen/EWIEGA46WW/qrc_qml.cpp.s:
$(MAKE) -f CMakeFiles/t2.dir/build.make CMakeFiles/t2.dir/t2_autogen/EWIEGA46WW/qrc_qml.cpp.s
.PHONY : t2_autogen/EWIEGA46WW/qrc_qml.cpp.s
t2_autogen/mocs_compilation.o: t2_autogen/mocs_compilation.cpp.o
.PHONY : t2_autogen/mocs_compilation.o
# target to build an object file
t2_autogen/mocs_compilation.cpp.o:
$(MAKE) -f CMakeFiles/t2.dir/build.make CMakeFiles/t2.dir/t2_autogen/mocs_compilation.cpp.o
.PHONY : t2_autogen/mocs_compilation.cpp.o
t2_autogen/mocs_compilation.i: t2_autogen/mocs_compilation.cpp.i
.PHONY : t2_autogen/mocs_compilation.i
# target to preprocess a source file
t2_autogen/mocs_compilation.cpp.i:
$(MAKE) -f CMakeFiles/t2.dir/build.make CMakeFiles/t2.dir/t2_autogen/mocs_compilation.cpp.i
.PHONY : t2_autogen/mocs_compilation.cpp.i
t2_autogen/mocs_compilation.s: t2_autogen/mocs_compilation.cpp.s
.PHONY : t2_autogen/mocs_compilation.s
# target to generate assembly for a file
t2_autogen/mocs_compilation.cpp.s:
$(MAKE) -f CMakeFiles/t2.dir/build.make CMakeFiles/t2.dir/t2_autogen/mocs_compilation.cpp.s
.PHONY : t2_autogen/mocs_compilation.cpp.s
# Help Target
help:
#echo "The following are some of the valid targets for this Makefile:"
#echo "... all (the default if no target is provided)"
#echo "... clean"
#echo "... depend"
#echo "... rebuild_cache"
#echo "... t2"
#echo "... edit_cache"
#echo "... t2_autogen"
#echo "... main.o"
#echo "... main.i"
#echo "... main.s"
#echo "... t2_autogen/EWIEGA46WW/qrc_qml.o"
#echo "... t2_autogen/EWIEGA46WW/qrc_qml.i"
#echo "... t2_autogen/EWIEGA46WW/qrc_qml.s"
#echo "... t2_autogen/mocs_compilation.o"
#echo "... t2_autogen/mocs_compilation.i"
#echo "... t2_autogen/mocs_compilation.s"
.PHONY : help
#=============================================================================
# Special targets to cleanup operation of make.
# Special rule to run CMake to check the build system integrity.
# No rule that depends on this can have commands that come from listfiles
# because they might be regenerated.
cmake_check_build_system:
$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
.PHONY : cmake_check_build_system
when i try to build it with makei get
C:\projects\t2>make
[ 16%] Automatic MOC and UIC for target t2
[ 16%] Built target t2_autogen
[ 33%] Automatic RCC for qml.qrc
Scanning dependencies of target t2
[ 50%] Building CXX object CMakeFiles/t2.dir/t2_autogen/mocs_compilation.cpp.o
[ 66%] Building CXX object CMakeFiles/t2.dir/main.cpp.o
[ 83%] Building CXX object CMakeFiles/t2.dir/t2_autogen/EWIEGA46WW/qrc_qml.cpp.o
[100%] Linking CXX executable t2.exe
CMakeFiles/t2.dir/main.cpp.o:main.cpp:
(.text$_ZN15QTypedArrayDataItE10deallocateEP10QArrayData[_ZN15QTypedArrayDataItE10deallocateEP10QArrayData]+0x1c): undefined reference to `QArrayData::deallocate(QArrayData*, unsigned long, unsigned long)'
CMakeFiles/t2.dir/main.cpp.o:main.cpp:(.text$_ZN15QTypedArrayDataItE10deallocateEP10QArrayData[_ZN15QTypedArrayDataItE10deallocateEP10QArrayData]+0x1c): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `QArrayData::deallocate(QArrayData*, unsigned long, unsigned long)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/t2.dir/build.make:126: t2.exe] Error 1
make[1]: *** [CMakeFiles/Makefile2:77: CMakeFiles/t2.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
Here source code of program:
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.load(url);
return app.exec();
}
Ok, i fix it, it seems that Ninja tool cause all problems under windows!
I remove all files from my simple project, so it contains only this files:
CMakeLists.txt
Makefile
main.cpp
main.qml
qml.qrc
In Qtcreator i go to Tools - > Options -> Kits
CMake generator -> MSYS Makefile
In Cmake tool select with path C:\msys64\mingw64\bin\cmake.exe or you maybe need to add it manually
After i press Ok and exit from options all works just fine. CMAKE configure project and compile it and it runs.
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.