Qt5 / Eclipse / Linux Problems with conversion from Qt4 to Qt5 - linux

I tried to convert a project from Qt4 to Qt5. Until now stackoverflow search and Google helped me, but now i'm stuck.
I have rewritten the cmake files and all includes to the new Qt header are placed. Also the library should be added correctly. In my eclipse project all header are found but for some objects eclipse underlines in red with following comment:
Symbol XXX could not be resolved
XXX is for example:
QMainWindow
QWidget
QGroupBox
other objects like QPushButton, QLineEdit are not underlined.
To be honest above the switch from Qt4 to Qt5, I switched from Win/VS10 to Linux/Eclipse.
So anyone can give me a hint ?
Would really appreciate it.
Thanks
Edit: How I add Qt in cmake:
find_package(Qt5Widgets)
if (Qt5Widgets_FOUND)
message(STATUS "Qt5Widgets found.")
else (Qt5Widgets_FOUND)
message(STATUS "Qt5Widgets not found!")
endif (Qt5Widgets_FOUND)
find_package(Qt5OpenGL)
if (Qt5OpenGL_FOUND)
message(STATUS "QtOpenGl found.")
else (Qt5OpenGL_FOUND)
message(STATUS "QtOpenGL not found!")
endif (Qt5OpenGL_FOUND)
...
include_directories( ${Qt5Widgets_INCLUDES} ${Qt5OpenGL_INCLUDES})
add_executable(exp_test_qtTemplate ${files} )
target_link_libraries( exp_test_qtTemplate ${OPENGL_LIBRARIES} ${Boost_LIBRARIES} ${Qt5Widgets_LIBRARIES} ${Qt5OpenGL_LIBRARIES})
And this is somth strange in the qt generated moc File
#include <QtCore/qbytearray.h>
#include <QtCore/qmetatype.h>
#if !defined(Q_MOC_OUTPUT_REVISION)
#error "The header file 'GlViewer.h' doesn't include <QObject>."
#elif Q_MOC_OUTPUT_REVISION != 67
#error "This file was generated using the moc from 5.0.1. It"
#error "cannot be used with the include files from this version of Qt."
#error "(The moc has changed too much.)"
#endif
looks like a failed installation of Qt.

Related

CMake not finding Qt5 when trying to create Qt5 Project in CLion on Linux

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

linking mongocxx using cmakelists file in Linux

i am new to cmake and also to mongocxx. I have installed the mongocxx using the instructions given on the site http://mongocxx.org/mongocxx-v3/. My installatio is fine. Now I am trying to connect with mongodb using cmake in my project. When i write the following cmakelists.txt file
cmake_minimum_required(VERSION 3.15)
project(PROJECT_NAME)
set(CMAKE_CXX_STANDARD 14)
add_executable(PROJECT_NAME main.cpp)
find_package(libmongocxx REQUIRED)
find_package(libbsoncxx REQUIRED)
include_directories(${LIBMONGOCXX_INCLUDE_DIR})
include_directories(${LIBBSONCXX_INCLUDE_DIR})
include_directories("/usr/local/include/mongocxx/v_noabi")
include_directories("/usr/local/include/bsoncxx/v_noabi")
include_directories("/usr/local/include/libmongoc-1.0")
include_directories("/usr/local/include/libbson-1.0")
include_directories("/usr/local/lib")
target_link_libraries(PROJECT_NAME ${LIBMONGOCXX_LIBRARIES})
target_link_libraries(PROJECT_NAME ${LIBBSONCXX_LIBRARIES})
it gives me following error :
CMake Error at CMakeLists.txt:8 (find_package):
By not providing "Findlibmongocxx.cmake" in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
"libmongocxx", but CMake did not find one.
Could not find a package configuration file provided by "libmongocxx" with
any of the following names:
libmongocxxConfig.cmake
libmongocxx-config.cmake
Add the installation prefix of "libmongocxx" to CMAKE_PREFIX_PATH or set
"libmongocxx_DIR" to a directory containing one of the above files. If
"libmongocxx" provides a separate development package or SDK, be sure it
has been installed.
-- Configuring incomplete, errors occurred!
See also "/home/fedora/testmongo/build/CMakeFiles/CMakeOutput.log".
I also tried to run my cpp file with this method given on above website.
code of my cpp file is
#include <cstdint>
#include <iostream>
#include <vector>
#include <bsoncxx/json.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/stdx.hpp>
#include <mongocxx/uri.hpp>
#include <mongocxx/instance.hpp>
#include <bsoncxx/builder/stream/helpers.hpp>
#include <bsoncxx/builder/stream/document.hpp>
#include <bsoncxx/builder/stream/array.hpp>
using bsoncxx::builder::stream::close_array;
using bsoncxx::builder::stream::close_document;
using bsoncxx::builder::stream::document;
using bsoncxx::builder::stream::finalize;
using bsoncxx::builder::stream::open_array;
using bsoncxx::builder::stream::open_document;
mongocxx::instance instance{}; // This should be done only once.
int main() {
std::cout << "Hello, World!" << std::endl;
mongocxx::client conn{ mongocxx::uri{ "mongodb://localhost:27017" } };
auto coll = conn["test"]["coll"];
std::vector<bsoncxx::document::value> documents;
for(int i = 0; i < 100; i++) {
documents.push_back(bsoncxx::builder::stream::document{} << "i" << i
<< finalize);
}
coll.insert_many(documents);
return 0;
}
and im trying to compile it with this command. its not giving any error
c++ --std=c++11 .cpp
-I/usr/local/include/mongocxx/v_noabi -I/usr/local/include/libmongoc-1.0
-I/usr/local/include/bsoncxx/v_noabi -I/usr/local/include/libbson-1.0
-L/usr/local/lib -lmongocxx -lbsoncxx
It complies without any errors and also generate output file a.out, but i don't know how to run that output file. its not running with
./a.out
gives following error
./a.out: error while loading shared libraries:
libmongocxx.so._noabi: cannot open shared object file: No such file
or directory """" This is the exact error i got
what should i do to correct this error or run the below executable file?
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/mongo-cxx-driver/lib64
These step resolved my problem
Use this as your CMakeLists.txt. Change $YOUR_PROJECT_NAME with your project's name.
cmake_minimum_required(VERSION 3.5)
if(POLICY CMP0025)
cmake_policy(SET CMP0025 NEW)
endif()
project($YOUR_PROJECT_NAME CXX)
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
endif()
set(CMAKE_CXX_EXTENSIONS OFF)
if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror")
endif()
find_package(mongocxx REQUIRED)
add_executable(${PROJECT_NAME} main.cpp)
# Visual Studio pre 2017 requires boost polyfill.
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND CMAKE_CXX_STANDARD LESS 17)
find_package(Boost 1.56.0 REQUIRED)
if (CMAKE_VERSION VERSION_LESS 3.15.0)
target_include_directories(${PROJECT_NAME} PRIVATE ${Boost_INCLUDE_DIRS})
else()
target_link_libraries(${PROJECT_NAME} PRIVATE Boost::boost)
endif()
endif()
target_link_libraries(${PROJECT_NAME}
PRIVATE mongo::mongocxx_shared
)
add_custom_target(run
COMMAND ${PROJECT_NAME}
DEPENDS ${PROJECT_NAME}
WORKING_DIRECTORY ${CMAKE_PROJECT_DIR}
)
get_target_property(LIBMONGOCXX_DEFINITIONS mongo::mongocxx_shared INTERFACE_COMPILE_DEFINITIONS)
list(FIND LIBMONGOCXX_DEFINITIONS "BSONCXX_STATIC" LIST_IDX)
if (${LIST_IDX} GREATER -1)
message(FATAL_ERROR "Expected BSONCXX_STATIC to not be defined")
endif()
list(FIND LIBMONGOCXX_DEFINITIONS "MONGOCXX_STATIC" LIST_IDX)
if (${LIST_IDX} GREATER -1)
message(FATAL_ERROR "Expected MONGOCXX_STATIC to not be defined")
endif()

Incorrect Dynamic Libraries linking after explicit set in Cmake

I've got a very frustrating issue a the moment. I'm attempting to build an executable that uses ROS and a compiled Matlab .so file. Due to what I believe is a boost conflict, I'm trying to build this exe using an earlier version of boost. Now, I've set up the cmakelist file, ran catkin_make (as its a ros project) and everything compiles, and the correct boost version is seen.
However, when running a ldd on the compiled exe, it still seems to be linking to the more recent version. Its rather annoying. I've posted the cmakelists file, and the ldd outcome. My system is Ubuntu 14.04 with ROS Indigo.
Any help would be really good, as I'm pulling my hair out trying to figure out what is wrong!
Many thanks in advance!
##CMAKE FILE
cmake_minimum_required(VERSION 2.8.3)
project(testmatlabdll)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wfatal-errors -O4 -march=native")
add_definitions(-std=c++11)
find_package(catkin REQUIRED)
find_package(PCL 1.7 REQUIRED)
link_directories(${PCL_LIBRARY_DIRS})
include_directories(${PCL_INCLUDE_DIRS})
add_definitions(${PCL_DEFINITIONS})
set(Boost_NO_SYSTEM_PATHS ON)
set(BOOST_ROOT /home/devbot/Downloads/boost_1_50_0)
set(BOOST_DIR /home/devbot/Downloads/boost_1_50_0)
set(Boost_INCLUDE_DIR /home/devbot/Downloads/boost_1_50_0)
set(BOOST_INCLUDEDIR /home/devbot/Downloads/boost_1_50_0)
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
message(STATUS "BOOST_ROOT = ${BOOST_ROOT}")
message(STATUS "Boost_VERSION = ${Boost_VERSION}")
message(STATUS "Boost_LIB_VERSION = ${Boost_LIB_VERSION}")
message(STATUS "Boost_MAJOR_VERSION = ${Boost_MAJOR_VERSION}")
message(STATUS "Boost_MINOR_VERSION = ${Boost_MINOR_VERSION}")
message(STATUS "Boost_LIBRARIES = ${Boost_LIBRARIES}")
message(STATUS "Boost_INCLUDE_DIRS = ${Boost_INCLUDE_DIRS}")
message(STATUS "Boost_LIBRARY_DIRS = ${Boost_LIBRARY_DIRS}")
find_package(Boost COMPONENTS REQUIRED
system filesystem thread date_time iostreams serialization chrono)
find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs message_generation image_transport cv_bridge)
find_package(OpenCV REQUIRED)
catkin_package(CATKIN_DEPENDS roscpp
std_msgs
pcl_ros
sensor_msgs
cv_bridge
message_runtime
LIBRARIES ${PROJECT_NAME}
DEPENDS system_lib)
include_directories(include ${catkin_INCLUDE_DIRS})
include_directories(${OpenCV_INCLUDE_DIRS})
include_directories(/usr/local/MATLAB/R2013b/extern/include/)
include_directories(/opt/matlab/extern/include)
include_directories(/home/devbot/catkin_ws/src/testmatlabdll/src)
link_directories(/home/devbot/catkin_ws/src/testmatlabdll/src)
add_library(mwmc SHARED IMPORTED)
set_property(TARGET mwmc PROPERTY IMPORTED_LOCATION /usr/local/MATLAB/MATLAB_Compiler_Runtime/v82/runtime/glnxa64/libmwmclmcrrt.so)
add_executable(testMatlab src/testMatlab.cpp)
target_link_libraries(testMatlab ${Boost_LIBRARIES} ${catkin_LIBRARIES} ${PCL_LIBRARIES} ${OpenCV_LIBRARIES})
target_link_libraries(testMatlab roughlib mwmc)
OUTPUT FROM LDD
ldd testMatlab | grep boost
libboost_system.so.1.50.0 => /home/devbot/Downloads/boost_1_50_0/stage/lib/libboost_system.so.1.50.0 (0x00007f7456f8a000)
libboost_system.so.1.54.0 => /usr/lib/x86_64-linux-gnu/libboost_system.so.1.54.0 (0x00007f7454662000)
libboost_thread.so.1.54.0 => /usr/lib/x86_64-linux-gnu/libboost_thread.so.1.54.0 (0x00007f745444c000)
libboost_filesystem.so.1.54.0 => /usr/lib/x86_64-linux-gnu/libboost_filesystem.so.1.54.0 (0x00007f7454018000)
libboost_regex.so.1.54.0 => /usr/lib/x86_64-linux-gnu/libboost_regex.so.1.54.0 (0x00007f744d5d8000)

include not found, how to fix with cmake?

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.

qplatformdefs.h with cmake

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.

Resources