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)
Related
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 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?
I'm trying to run travis test,but I get the following error.
I checked my files and directories, all files are exist.
I think my mistake in cmake file, but I can't find it.
Maybe someone can help me?
make[1]: *** No rule to make target CMakeFiles/test.dir/all', needed byCMakeFiles/Examples.dir/all'. Stop.
cmake_minimum_required(VERSION 2.8.7)
project(test)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
option(BUILD_SHARED_LIBS "Build shared instead of static library" OFF)
option(BUILD_TESTS "Build tests for webdavclient" ON)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/tests/ /sources)
add_library(test STATIC ${CMAKE_CURRENT_SOURCE_DIR}/sources/client.cpp tests/main.cpp)
find_package(OpenSSL REQUIRED)
find_package(Boost REQUIRED)
find_package(CURL REQUIRED)
include_directories(${CURL_INCLUDE_DIR})
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(test ${Boost_LIBRARIES})
endif()
if(UNIX)
set(DEPENDS_LIBRARIES ${OPENSSL_LIBRARIES} ${CURL_LIBRARY} ${Boost_LIBRARIES})
elseif(MSVC)
set(DEPENDS_LIBRARIES ${OPENSSL_LIBRARIES} ${CURL_LIBRARY} ${Boost_LIBRARIES} ws2_32)
endif()
add_executable(Examples ${CMAKE_CURRENT_SOURCE_DIR}/examples/main.cpp)
target_link_libraries(Examples ${PROJECT_NAME} ${DEPENDS_LIBRARIES})
if(BUILD_TESTS)
enable_testing()
file(GLOB ${PROJECT_NAME}_TEST_SOURCES tests/*.cpp)
add_executable(init ${${PROJECT_NAME}_TEST_SOURCES})
target_link_libraries(init ${PROJECT_NAME} ${DEPENDS_LIBRARIES})
add_test(NAME init COMMAND init "-s" "-r" "compact" "--use-colour" "yes")
endif()
Command enable_testing() among other things creates target test. But you already have library target with the same name. This confuses CMake. For avoid this, rename library target.
Also, it is not recommended to have target name same as the project. So, rename project too.
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.
I am trying to compile my game project using Clion IDE but I have a problem when porting allegro 5. I get this error:
main.cpp:2:10: fatal error: 'allegro/allegro.h' file not found
#include <allegro/allegro.h>
My CMakeLists is:
cmake_minimum_required(VERSION 3.5)
project(testAllegro)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(testAllegro ${SOURCE_FILES})
INCLUDE_DIRECTORIES( /usr/local/include )
LINK_DIRECTORIES( /usr/local/lib )
file(GLOB LIBRARIES "/usr/local/Cellar/allegro/5.2.1.1_1/lib/*.dylib")
message("LIBRARIES = ${LIBRARIES}")
TARGET_LINK_LIBRARIES(testAllegro ${LIBRARIES})
Just I want to ask how can I add external Library allegro to Clion?
when you install allegro using homebrew link
use this cmake to compile clion project
cmake_minimum_required(VERSION 3.5)
project(testAllegro)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(testAllegro ${SOURCE_FILES})
INCLUDE_DIRECTORIES( /usr/local/Cellar/allegro/5.2.1.1_1/include )
LINK_DIRECTORIES( /usr/local/Cellar/allegro/5.2.1.1_1/lib )
file(GLOB LIBRARIES "/usr/local/Cellar/allegro/5.2.1.1_1/lib/*.dylib")
message("LIBRARIES = ${LIBRARIES}")
TARGET_LINK_LIBRARIES(testAllegro ${LIBRARIES})