I'm trying to compile my Qt program with cmake but I've got an arror when compiling qzip.cpp :
qzip.cpp:57:27: error fatal: qplatformdefs.h: No such file or directory
I've added these lines in CMakeLists.txt but it didn't work :
IF (QT_LIBRARY_DIR AND NOT QT_MKSPECS_DIR OR QT_QMAKE_CHANGED)
EXEC_PROGRAM( ${QT_QMAKE_EXECUTABLE}
ARGS "-query QMAKE_MKSPECS"
OUTPUT_VARIABLE qt_mkspecs_dirs )
# do not replace : on windows as it might be a drive letter
# and windows should already use ; as a separator
IF(UNIX)
STRING(REPLACE ":" ";" qt_mkspecs_dirs "${qt_mkspecs_dirs}")
ENDIF(UNIX)
SET(QT_MKSPECS_DIR NOTFOUND)
FIND_PATH(QT_MKSPECS_DIR qconfig.pri PATHS ${qt_mkspecs_dirs}
DOC "The location of the Qt mkspecs containing qconfig.pri"
NO_DEFAULT_PATH )
ENDIF (QT_LIBRARY_DIR AND NOT QT_MKSPECS_DIR OR QT_QMAKE_CHANGED)
SET( QT_INCLUDES ${QT_QT_INCLUDE_DIR} ${QT_MKSPECS_DIR}/default ${QT_INCLUDE_DIR} )
So, how can I add a link to qplatformdefs.h in my CMakeLists.cpp?
Thanks a lot.
P.S.: I'm on Ubuntu 12.04 32bits
You can try to add this to your CMakeLists.txt:
include_directories(${QT_MKSPECS_DIR}/default)
You may have already found the answer, but in case you have not found it here is the thing:
In my Fedora, this file is located in /usr/lib64/qt4/mkspecs/linux-g++-64.
Assuming that its the same location in Ubuntu, you should add this dir to the include_directories();
include_directories( lots_of_dirs "/usr/lib64/qt4/mkspecs/linux-g++-64/")
I hope I have helped.
Related
I am getting the following CMake error:
CMake Error at CMakeLists.txt:23 (find_package):
By not providing "FindQt5.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Qt5", but
CMake did not find one.
Could not find a package configuration file provided by "Qt5" with any of
the following names:
Qt5Config.cmake
qt5-config.cmake
Add the installation prefix of "Qt5" to CMAKE_PREFIX_PATH or set "Qt5_DIR"
to a directory containing one of the above files. If "Qt5" provides a
separate development package or SDK, be sure it has been installed.
In my CMakeLists.txt, there is this line:
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 ()
So I did what it says and set my PREFIX_PATH to "/usr/include/x86_64-linux-gnu/qt5/".
However, the error I get says that CMake cannot find "qt5-config.cmake", which is located at "/usr/lib/x86_64-linux-gnu/cmake/Qt5" and not "/usr/include/x86_64-linux-gnu/qt5/", so I tried setting the "Qt5_DIR" to that directory (since it says in the error to set it to a dir that contains the above files) but still without success. Any ideas why it cant find the files it needs?
edit:
my CMakeLists.txt:
cmake_minimum_required(VERSION 3.19)
project(untitled1)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_PREFIX_PATH "/usr/lib/x86_64-linux-gnu/cmake/Qt5/")
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(QT_VERSION 5)
set(REQUIRED_LIBS Core Gui Widgets)
set(REQUIRED_LIBS_QUALIFIED Qt5::Core Qt5::Gui Qt5::Widgets)
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})
note that the file has been auto-generated by CLion, all I did was change the path according to what is specified in the if-Block
# Try to find IntelIPP
# Once done, this will define
#
# Ipp_FOUND - system has IntelIPP
# Ipp_INCLUDE_DIR - the IntelIPP include directories
# Ipp_LIBRARY - link these to use IntelIPP
include(LibFindMacros)
set(IPP_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../libs/intel/linux/intel_ipp)
# Include dir
find_path(Ipp_INCLUDE_DIR
NAMES ipp.h
PATHS ${IPP_ROOT_DIR}/include
)
find_library(Ipp_IRC_LIB
NAMES irc
PATHS ${IPP_ROOT_DIR}/lib/ia32
)
find_library(Ipp_MAT_LIB
NAMES ippm
PATHS ${IPP_ROOT_DIR}/lib/ia32
)
list(APPEND Ipp_LIBRARY ${Ipp_IRC_LIB} ${Ipp_MAT_LIB} )
include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set Ipp_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args(Ipp DEFAULT_MSG
Ipp_LIBRARY Ipp_INCLUDE_DIR)
# Set the include dir variables and the libraries and let libfind_process do the rest.
# NOTE: Singular variables for this library
set(Ipp_INCLUDE_DIRS ${Ipp_INCLUDE_DIR})
set(Ipp_LIBRARIES ${Ipp_LIBRARY})
My FindIpp.cmake script is shown above. On windows, I get
-- Could NOT find IPP (missing: IPP_INCLUDE_DIR IPP_LIBRARY). I've tested this under Linux and it works without any issues. In both cases, I'm trying to cross-compile using the QNX Momentics toolchain.
The ${CMAKE_CURRENT_SOURCE_DIR} is the location of the 'root' script which does include(FindIpp).
I've looked at the output of ${CMAKE_CURRENT_SOURCE_DIR} and the output of the relative paths to make sure that the files and folders exist in the reported paths. ${CMAKE_CURRENT_SOURCE_DIR}/../libs/intel shows up as C:/../libs/intel.
I use CMake 3.5 on Linux and CMake 3.6.1 on Windows 7.
From a cmd prompt, I could type in 'cd c:/libs/intel' without any issues.
I tried hardcoding the IPP_ROOT_DIR path to set(IPP_ROOT_DIR C:/libs/intel/linux/intel_ipp), tried adding quotes around the path, appended CACHE PATH "Description" to the set call. None of these worked.
I tried -GNinja, -G "MinGW Makefiles" and -G "Unix Makefiles". Still came up with:
-- Could NOT find IPP (missing: IPP_INCLUDE_DIR IPP_LIBRARY)
-- Could NOT find Mkl (missing: Mkl_LIBRARY Mkl_INCLUDE_DIR)
-- Could NOT find Boost (missing: Boost_LIBRARY Boost_INCLUDE_DIR)
-- Could NOT find GTest (missing: GTEST_LIBRARY GTEST_MAIN_LIBRARY)
Copying and pasting contents from individual files like FindIpp.cmake into the main CMakeLists.txt file finds the libraries, but not the path to includes. Now I've also added list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SRC_DIR}/CMake/Modules) to find my module files. If I remove that line, cmake throws an error at include(FindIpp).
Is there anything obvious that I'm doing wrong? Also, is this the way to write a find_library or find_path? Thanks
So the correct way to cross-compile to QNX from Windows and Linux:
cmake -DCMAKE_SYSTEM_NAME="QNX" -DCMAKE_SYSTEM_VERSION="660" -DCMAKE_SYSTEM_PROCESSOR="x86" -GNinja path_to_project
Where 660 is QNX version 6.6.0. I was using my own Toolchain file for QNX. This is not necessary. There is one already provided under share/cmake-/Modules/Platform. So as long as we define the above CMAKE variable somewhere, you should be good to go.
I am creating an object tracking program which rely on OpenCV. Thus I want to be able to test it with different versions of OpenCV but I have linking errors.
I installed the last version of OpenCV (a69b435c928f422fb5f99c02cf2dcae57dcf820a) in the following folder : /usr/local/opencv/opencv-trunk instead of the usual /usr/local.
Then I followed also the official tutorial to use OpenCV with CMake in Linux, but I had the following "normal" error :
CMake Error at CMakeLists.txt:11 (find_package):
By not providing "FindOpenCV.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "OpenCV", but CMake did not find one.
Could not find a package configuration file provided by "OpenCV" with any of the following names:
OpenCVConfig.cmake
opencv-config.cmake
Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set "OpenCV_DIR" to a directory containing one of the above files. If "OpenCV" provides a separate development package or SDK, be sure it has been installed.
-- Configuring incomplete, errors occurred!
So I did what was suggested and added the following line in my CMakeLists.txt :
# Find independently installed OpenCV libraries
set(OpenCV_DIR "/usr/local/opencv/opencv-trunk/share/OpenCV")
This is the complete CMakeLists.txt file :
# Find independently installed OpenCV libraries
set(OpenCV_DIR "/usr/local/opencv/opencv-trunk/share/OpenCV")
cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
add_executable( DisplayImage DisplayImage.cpp )
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )
Now I have the following error and I don't find how to deal with it.
CMake Error at CMakeLists.txt:12 (find_package):
Found package configuration file:
/usr/local/opencv/opencv-trunk/share/OpenCV/OpenCVConfig.cmake
but it set OpenCV_FOUND to FALSE so package "OpenCV" is considered to be NOT FOUND.
-- Configuring incomplete, errors occurred!
If you have already faced that issue in such context your solutions are welcomed ;)
If you are running IntelliJ or any other IDE, just try re-building CMake cache (or just remove your build directory and run cmake utility again).
I believe this is not the best practice - to set the configuration variable like OpenCV_DIR hard-coded in the CMakeLists.txt. Try setting it manually, as an environment variable to the cmake utility:
OpenCV_DIR=/usr/local/Cellar/opencv3/3.1.0_2/share/OpenCV/ cmake ..
or set your IDE to make this for you:
there my CMakeLists.txt :
cmake_minimum_required( VERSION 2.8 )
set (CMAKE_VERBOSE_MAKEFILE ON)
project( a.out )
find_package(OpenGL)
find_package(PkgConfig REQUIRED)
pkg_search_module(GLFW REQUIRED glfw3)
pkg_search_module(CEGUI-GL REQUIRED CEGUI-0-OPENGL)
pkg_search_module(CEGUI REQUIRED CEGUI-0)
macro( config_project PROJNAME LIBNAME )
include_directories( ${${LIBNAME}_INCLUDE_DIR} )
target_link_libraries( ${PROJNAME} ${${LIBNAME}_LIBRARIES} )
endmacro()
add_definitions(-std=c++11)
add_executable(a.out src/ConsoleWindow.cc src/camera.cc src/main.cc)
config_project(a.out OPENGL)
config_project(a.out GLFW)
config_project(a.out CEGUI-GL)
config_project(a.out CEGUI)
so, there is PkgConfig for CEGUI-0-OPENGL and CEGUI-0. In CEGUI-0.pc there is:
prefix=/usr
exec_prefix=${prefix}
libdir=${prefix}/lib
includedir=${prefix}/include/cegui-0
moduledir=${prefix}/lib/cegui-0.8
datafiles=${prefix}/share/cegui-0
Name: CEGUI-0
Description: The free GUI library for games and multi-media development.
Version: 0.8.2
Libs: -L${libdir} -lCEGUIBase-0
Cflags: -I${includedir} -I${includedir}/cegui
when I run cmake . everything is fine, but in one of my .cc I have :
#include <CEGUI/CEGUI.h>
and when I compil the file I got an error like no such file found... but locate return :
/usr/include/cegui-0/CEGUI/CEGUI.h
what I'm doing wrong ?
I had the same problem, and did not find a clean solution. I solved like this:
include_directories(${CEGUI_INCLUDE_DIR}/../)
which is probably not the best solution, but enough for me...
some months later...
I think I solved this problem, I changed the line
include_directories( ${${LIBNAME}_INCLUDE_DIR} )
by
include_directories( ${${LIBNAME}_INCLUDEDIR} )
after noticing how includedir is typed in CEGUI-0.pc ...
includedir=${prefix}/include/cegui-0
I don't get the "no file found error" for #include <CEGUI/CEGUI.h> anymore. I will try to do a hell-o world with CEGUI in my program next days. If you have any comment plz do.
I am perplexed and would like your help.
I am cross compiling a project that requires ifaddrs.h, but no matter how I try to specify the location of the file, it never finds it. It is located at /usr/include/ifaddrs.h and I have used the code below to try to point to it. (Granted this is the host system's file, but that should not matter in this context. I have also put the file in the target systems include directory: /tmp/toolchain/include with no different results). And the message call does print /usr/include
If, however, I put the file in ${CMAKE_CURRENT_SOURCE_DIR}/../include
it is found. It is there, I can see it -- why not cmake?
FIND_FILE( IFADDRS ifaddrs.h PATH /usr/include )
get_filename_component(if_path ${IFADDRS} PATH)
message( "IFADDRS = " ${if_path} )
include_directories( ${if_path} )
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/../include )
Changing the code above to this:
include_directories( BEFORE SYSTEM /usr/include )
and running make VERBOSE=1 gives this:
[ 18%] Building C object CMakeFiles/cpcommon_lib.dir/eui48.c.o
/tmp/toolchain/arm-linux-uclibc/bin/gcc -DPJ_AUTOCONF=1 -DPJ_IS_BIG_ENDIAN=0 -DPJ_IS_LITTLE_ENDIAN=1 -I/home/bp/MySnapCam/projects/Communication/trunk/cpcommon/src/../include -I/home/bp/MySnapCam/projects/Communication/trunk/cpcommon/src/../../pjproject/pjlib-util/include -I/home/bp/MySnapCam/projects/Communication/trunk/cpcommon/src/../../pjproject/pjlib/include -I/home/bp/MySnapCam/projects/Communication/trunk/cpcommon/src/../../pjproject/pjnath/include -I/usr/include/w32api -I/usr/X11R6/include -I/usr/include/X11 -I/usr/pkg/include -I/opt/csw/include -I/opt/include -I/usr/openwin/include -I/home/bp/MySnapCam/projects/Communication/trunk/cpcommon/src/../../cjson -o CMakeFiles/cpcommon_lib.dir/eui48.c.o -c /home/bp/MySnapCam/projects/Communication/trunk/cpcommon/src/eui48.c
In file included from /home/bp/MySnapCam/projects/Communication/trunk/cpcommon/src/eui48.c:26:
/home/bp/MySnapCam/projects/Communication/trunk/cpcommon/src/impl/eui48_unix.c:14:21: ifaddrs.h: No such file or directory
There is no /usr/include/ in the include paths. It is also not in the flags.make files either.