Seems to me that QT5 libraries were not linked correctly when linking them with cmake.
I have a cmake file that set an option to use QT4 or QT5:
if(USE_Qt5)
if(NOT Qt5_PREFIX_PATH)
set(Qt5_PREFIX_PATH /Applications/Qt/5.2.1/clang_64)
endif(NOT Qt5_PREFIX_PATH)
set(WINSDK_LIB_DIR
"C:/Program Files (x86)/Windows Kits/8.0/Lib/win8/um/x64"
"C:/Program Files (x86)/Microsoft SDKs/Windows/v7.0A/Lib"
)
set(CMAKE_PREFIX_PATH ${3RDPARTY} ${Qt5_PREFIX_PATH} ${WINSDK_LIB_DIR} ${CMAKE_PREFIX_PATH})
message(STATUS "Qt5 prefix path set to: ${CMAKE_PREFIX_PATH}")
find_package(Qt5Widgets)
find_package(Qt5OpenGL)
endif(USE_Qt5)
if(USE_Qt4)
file(GLOB QT4ROOTS ${3RDPARTY}/Qt/*/bin)
find_program(QT_QMAKE_EXECUTABLE NAMES qmake qmake4 qmake-qt4 PATHS ${QT4ROOTS})
find_package(Qt4 REQUIRED)
set(QT_USE_QTOPENGL TRUE)
endif(USE_Qt4)
if qt4 is selected no problems, compile and execute.
Compiling Qt5 return quite a lot of errors that seems to me a linking problem:
/Applications/Qt/5.2.1/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:52:24: error: variable has incomplete type 'class Q_WIDGETS_EXPORT'
class Q_WIDGETS_EXPORT QSizePolicy
^
/Applications/Qt/5.2.1/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:52:7: note: forward declaration of 'Q_WIDGETS_EXPORT'
class Q_WIDGETS_EXPORT QSizePolicy
^
/Applications/Qt/5.2.1/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:52:35: error: expected ';' after top level declarator
class Q_WIDGETS_EXPORT QSizePolicy
^
;
/Applications/Qt/5.2.1/clang_64/lib/QtWidgets.framework/Headers/qsizepolicy.h:163:31: error: expected a class or namespace
Q_DECLARE_OPERATORS_FOR_FLAGS(QSizePolicy::ControlTypes)
???
here is were i link the libraries:
if(USE_Qt4 OR USE_Qt5)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
# disable autolinking to qmain
cmake_policy(SET CMP0020 OLD)
set(USE_QT true)
add_definitions(-DWITH_QT)
endif(USE_Qt4 OR USE_Qt5)
if(USE_Qt5)
#target_link_libraries(myProject
# Qt5::Widgets
#)
qt5_use_modules(myProject Widgets)
endif(USE_Qt5)
Related
Error from Terminal:
ics45c#ics45c-2019fall : ~/projects/proj1 $ ./build app
-- Configuring done
CMake Error at CMakeLists.txt:49 (add_executable):
Cannot find source file:
/home/ics45c/projects/proj1/app/.#main.cpp
Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
.hxx .in .txx
CMake Error: CMake can not determine linker language for target: a.out.gtest
CMake Error: Cannot determine link language for target "a.out.gtest".
CMake Error: CMake can not determine linker language for target: a.out.app
CMake Error: Cannot determine link language for target "a.out.app".
CMake Error: CMake can not determine linker language for target: a.out.exp
CMake Error: Cannot determine link language for target "a.out.exp".
-- Generating done
-- Build files have been written to: /home/ics45c/projects/proj1/out
I checked my file manager and main.cpp and #main.cpp# are in the location /home/ics45c/projects/proj1/app
Also I don't understand the other CMake errors after CMakeLists.txt either. What does it mean that it can't determine the linker language?
## Here is the CMakeLists.txt file ##
cmake_minimum_required(VERSION 3.10)
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(COMPILE_FLAGS "-stdlib=libc++ -Wall -pedantic-errors -Werror -g -fstandalone-debug")
project(a.out.app)
file(GLOB APP_SRC_FILES ${CMAKE_SOURCE_DIR}/app/*.cpp)
set(APP_SRC_FILES_EXCEPT_MAIN ${APP_SRC_FILES})
list(REMOVE_ITEM APP_SRC_FILES_EXCEPT_MAIN ${CMAKE_SOURCE_DIR}/app/main.cpp)
add_executable(${PROJECT_NAME} ${APP_SRC_FILES})
set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS ${COMPILE_FLAGS})
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/app)
target_link_libraries(${PROJECT_NAME} pthread c++)
project(a.out.exp)
file(GLOB EXP_SRC_FILES ${CMAKE_SOURCE_DIR}/exp/*.cpp)
add_executable(${PROJECT_NAME} ${EXP_SRC_FILES} ${APP_SRC_FILES_EXCEPT_MAIN})
set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS ${COMPILE_FLAGS})
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/app)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/exp)
target_link_libraries(${PROJECT_NAME} pthread c++)
project(a.out.gtest)
file(GLOB GTEST_SRC_FILES ${CMAKE_SOURCE_DIR}/gtest/*.cpp)
add_executable(${PROJECT_NAME} ${GTEST_SRC_FILES} ${APP_SRC_FILES_EXCEPT_MAIN})
set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS ${COMPILE_FLAGS})
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/app)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/gtest)
target_link_libraries(${PROJECT_NAME} pthread c++ gtest gtest_main)
Line 49 is the error according to the CMake error but I have no idea why:
add_executable(${PROJECT_NAME} ${GTEST_SRC_FILES} ${APP_SRC_FILES_EXCEPT_MAIN})
I just don't understand any of this, and this is also my first Stackoverflow post.
I am having this weird issue where the paths that I use for my include_directories and target_link_libraries has to be all lowercase.
My project has a subdirectory under it at GLTestBed/src if I try to include it , ninja (or even the built VS solution) throws an error
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ninja : error : '../../GLTestBed/src/Mesh.cpp', needed by 'GLTestBed/CMakeFiles/GlTestBed.dir/src/Mesh.cpp.obj', missing and no known rule to make it
Mesh.cpp is the first file added in my add_Library directive, if I remove that it throws this error for the file that is at top, so I am pretty sure its not an error for just this particular file
However if I change the folder name from GLTestBed to gltestbed every thing builds correctly
CmakeLists.txt in main Folder (GLParticles)
cmake_minimum_required(VERSION 3.10)
set(CMAKE_CXX_STANDARD 11)
project(GLParticles)
set (glparticlesdir "${CMAKE_CURRENT_SOURCE_DIR}/GLTestBed")
message ("-----" , ${glparticlesdir})
add_subdirectory(${glparticlesdir})
add_executable(GLParticles
src/main.cpp
src/ParticleWorld.cpp
src/ParticleWorld.h
src/BurstParticleUpdater.cpp
src/BurstParticleUpdater.h src/SineWaveUpdater.cpp src/SineWaveUpdater.h)
include_directories(${glparticlesdir}/src)
include_directories(${glparticlesdir}/ext/glm)
target_link_libraries(GLParticles
GlTestBed)
# SET(CMAKE_CXX_LINK_FLAGS "-framework OpenGL")
and the CmakeLists.txt in the GLTestBed folder
cmake_minimum_required(VERSION 3.10)
project(GlTestBed)
set(CMAKE_CXX_STANDARD 11)
find_package(OpenGL REQUIRED)
#find_package(GLEW REQUIRED)
message ('--------' ${OPENGL_LIBRARIES})
add_Library(GlTestBed
src/Globals.h
src/Mesh.cpp
src/Mesh.h
src/ResourceManager.cpp
src/ResourceManager.hpp
src/Shader.cpp
src/Shader.h
src/stb_image.cpp
src/stb_image.h
src/Material.h
src/Engine.cpp src/Engine.h
src/Particle.cpp
src/Particle.h
src/Camera.h
src/Camera.cpp
src/ParticleManager.cpp
src/ParticleManager.h
src/ParticleUpdater.h)
target_include_directories(GlTestBed PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
target_include_directories(GlTestBed PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/ext/glm)
target_link_libraries(GlTestBed
${OPENGL_LIBRARIES}
glew32.lib
sfml-graphics.lib
sfml-window.lib
sfml-system.lib)
if(APPLE)
target_include_directories(GlTestBed PUBLIC
/usr/local/include)
target_link_libraries(GlTestBed
/usr/local/Cellar/glew/2.1.0/lib/libGLEW.2.1.0.dylib
/usr/local/Cellar/sfml/2.4.2_1/lib/libsfml-window.2.4.2.dylib
/usr/local/Cellar/sfml/2.4.2_1/lib/libsfml-system.2.4.2.dylib ${OPENGL_LIBRARIES})
endif()
FindFoo.cmake:
# Foo_FOUND - system has Foo
# Foo_INCLUDE_DIRS - the Foo include directories
# Foo_LIBRARIES - link these to use Foo
# Foo_VERSION
# Foo_DEFINITIONS - compiler switches required for using Foo
find_package(PkgConfig)
pkg_check_modules(PC_Foo QUIET Foo)
find_path(Foo_INCLUDE_DIR Foo/Foo.h
PATHS ${PC_Foo_INCLUDEDIR} ${PC_Foo_INCLUDE_DIRS}
)
find_library(Foo_LIBRARY Foo
PATHS ${PC_Foo_LIBDIR} ${PC_Foo_LIBRARY_DIRS}
)
set(Foo_VERSION ${PC_Foo_VERSION})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Foo
FOUND_VAR Foo_FOUND
REQUIRED_VARS
Foo_LIBRARY
Foo_INCLUDE_DIR
VERSION_VAR Foo_VERSION
)
if(Foo_FOUND)
set(Foo_LIBRARIES ${Foo_LIBRARY})
set(Foo_INCLUDE_DIRS ${Foo_INCLUDE_DIR})
set(Foo_DEFINITIONS ${PC_Foo_CFLAGS_OTHER})
endif()
mark_as_advanced(
Foo_INCLUDE_DIR
Foo_LIBRARY
)
CMakeLists.txt:
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.8)
PROJECT(sandbox)
set(CMAKE_AUTOMOC ON)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
FIND_PACKAGE(Qt5Core REQUIRED)
find_package(Foo REQUIRED)
include_directories(${Foo_INCLUDE_DIRS})
SET(sandbox_SOURCES main.cpp)
ADD_EXECUTABLE(sandbox ${sandbox_SOURCES})
QT5_USE_MODULES(sandbox Core)
TARGET_LINK_LIBRARIES(sandbox ${Foo_LIBRARIES})
#include <Bar1.h> works in my program whereas #include <Foo/Bar1.h> doesn't. and the real problem is that i can't build my program because Bar1.h contains #include <Foo/Bar2.h> and:
...Foo/Bar1.h: fatal error: Foo/Bar2.h: No such file or directory
compilation terminated.
CMake 3.5.1
looks like the problem was CMake cache. i deleted everything from the CMakeFiles directory and then CMake couldn't configure the project:
Could NOT find Foo (missing: Foo_INCLUDE_DIR)
i had to add PATH_SUFFIXES to find_path(), and all the problems are gone.
I have a problem while I am writing the cmake file. I have a project which both uses the Qt and WinSock2. But when I add set(CMAKE_AUTOMOC ON) to the CMake code, it gives me these errors:
Error 4 error C2011: 'sockaddr' : 'struct' type
redefinition C:\Program Files (x86)\Microsoft
SDKs\Windows\v7.0A\include\ws2def.h 212 Error 5 error C2059: syntax
error : 'constant' C:\Program Files (x86)\Microsoft
SDKs\Windows\v7.0A\include\ws2def.h 390 Error 6 error C3805:
'constant': unexpected token, expected either '}' or a ',' C:\Program
Files (x86)\Microsoft SDKs\Windows\v7.0A\include\ws2def.h 390 ...
And my cmake file is as follows:
PROJECT(RFIDVis-core)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0 FATAL_ERROR)
#INCLUDE(../cmake/commonconf.cmake)
set(CMAKE_AUTOMOC ON)
#set(CMAKE_INCLUDE_CURRENT_DIR ON)
MESSAGE(STATUS "Configuring RFIDVis Source")
# glob sources from core directories
FILE(GLOB RFIDVisSources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
BusinessLogic/*.cpp
DataLayer/*.cpp
IrrlichtComponents/*.cpp
GeneratedFiles/Debug/*.cpp
Libraries/*.cpp
Presentation/*.cpp
main.cpp
)
FILE(GLOB RFIDVisHeaders RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
BusinessLogic/*.h
DataLayer/*.h
Libraries/*.h
Libraries/*.hpp
IrrlichtComponents/*.h
Presentation/*.h
)
FILE(GLOB CampvisApplicationForms
Presentation/*.ui
)
SET(RFIDVisApplicationToBeMocced
GeneratedFiles/ui_demomainwindow.h
)
#
# Qt related stuff:
#
QT5_WRAP_CPP(RFIDVisApplicationMoc ${RFIDVisApplicationToBeMocced})
LIST(APPEND RFIDVisApplicationSources ${RFIDVisApplicationMoc})
QT5_WRAP_UI(RFIDVisApplicationFormsHeaders ${RFIDVisApplicationForms})
LIST(APPEND RFIDVisApplicationSources ${RFIDVisApplicationFormsHeaders})
LINK_DIRECTORIES(${RFIDVisGlobalLinkDirectories} ${IRRLICHT_LIBRARY}
${RFIDVisHome}/ext/VISA/lib/msc/visa32.lib
${RFIDVisHome}/ext/VISA/lib/msc/rsspecan.lib
)
qt5_generate_moc(main.cpp main.moc)
ADD_EXECUTABLE(RFIDVis-application
${RFIDVisSources} ${RFIDVisHeaders} ${RFIDVisMocs}
)
ADD_DEFINITIONS(${RFIDVisGlobalDefinitions})
INCLUDE_DIRECTORIES(${RFIDVisGlobalIncludeDirs})
cmake_policy(SET CMP0020 NEW)
TARGET_LINK_LIBRARIES(RFIDVis-application Qt5::Core Qt5::Widgets ws2_32.lib
${RFIDVisHome}/ext/VISA/lib/msc/visa32.lib
${RFIDVisHome}/ext/VISA/lib/msc/rsspecan.lib
${IRRLICHT_LIBRARY})
qt5_use_modules(RFIDVis-application Core GUI Widgets)
DEFINE_SOURCE_GROUPS_FROM_SUBDIR(RFIDVisSources ${RFIDVisHome} "")
DEFINE_SOURCE_GROUPS_FROM_SUBDIR(RFIDVisHeaders ${RFIDVisHome} "")
The problem is that the windows.h is going to be added to the project after adding the AUTOMOC. So, the solution is to add add_definitions(-DWIN32_LEAN_AND_MEAN) to the cmake file. Then, the windows.h will not include the winsock and you can include it by yourself in your project
I'm trying to compile opencv_2.4.9 with cmake_3.5.0 to run a project in Qt_5.3.2 MinGW and it keeps showing this error:
Common needed but can't find boost
I choose "MinGW Makefiles" as generator and "specify native compilers" in configure window. I defined BOOST_ROOT environmental variable and this is my CmakeLists.txt:
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
SET(sampleName MyApp)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_STATIC ON)
set(Boost_COMPILER -gcc49)
SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "C:/Program Files/PCL 1.6.0/3rdParty/Boost/include")
SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "C:/Program Files/PCL 1.6.0/3rdParty/Boost/lib")
find_package(PCL 1.6.0 REQUIRED)
FIND_PACKAGE(Boost)
IF (Boost_FOUND)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
ADD_DEFINITIONS( "-DHAS_BOOST" )
ENDIF()
FIND_PACKAGE(MRPT REQUIRED base;bayes;obs;gui)
include_directories(${PCL_INCLUDE_DIRS})
include_directories("C:/Program Files/PCL 1.6.0/3rdParty/Boost/include")
link_directories(${PCL_LIBRARY_DIRS})
link_directories("C:/Program Files/PCL 1.6.0/3rdParty/Boost/lib")
add_definitions(${PCL_DEFINITIONS})
add_executable (MyApp Local.cpp part.h grab.h interface.h test.cpp test.h)
target_link_libraries (MyApp ${PCL_LIBRARIES} libeng.lib libmx.lib libmex.lib libmat.lib Aria.lib winmm.lib wsock32.lib)
TARGET_LINK_LIBRARIES(${sampleName}
${MRPT_LIBS} # This is filled by FIND_PACKAGE(MRPT ...)
"" # Optional extra libs...
)
Does anyone know what solves this error?
So what I did to solve this was first run Cmake as
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(pcd_write)
set(Boost_DEBUG ON)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_STATIC ON)
find_package(PCL 1.2 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable (pcd_write pcd_write.cpp)
target_link_libraries (pcd_write ${PCL_LIBRARIES})
And towards the bottom I saw
Boost include path: C:/Program Files/PCL 1.6.0/3rdParty/Boost/include
Could not find the following static Boost libraries:
boost_system
boost_filesystem
boost_thread
boost_date_time
boost_iostreams
I looked in that folder and sure enough I was missing the boost folders for them all.
There might be a better solution, but I just downloaded the latest version of Boost to my computer and replaced the entire C:/Program Files/PCL 1.6.0/3rdParty/Boost folder with the new one and everything worked for me
First of all, you can put
set(Boost_DEBUG ON)
before the command
FIND_PACKAGE(Boost)
This gives you some more output and helped me to find the source of other errors.
Next, I would try to set the variables BOOST_LIBRARYDIR and BOOST_INCLUDEDIR, e.g.
set(BOOST_LIBRARYDIR "C:/Program Files/PCL 1.6.0/3rdParty/Boost/lib")
set(BOOST_INCLUDEDIR "C:/Program Files/PCL 1.6.0/3rdParty/Boost/include")