2017-12-09 32 views
10

Poniższy CMakeList produkuje błędy, które zostały wymienione poniżej:Jak połączyć Qt 5.9 w ROS?

cmake_minimum_required(VERSION 2.8.12) 

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") 

set(CMAKE_INCLUDE_CURRENT_DIR ON) 
set(CMAKE_AUTOMOC ON) 
set(CMAKE_AUTORCC ON) 

project(draw_on_images) 

find_package(catkin REQUIRED COMPONENTS 
    roscpp 
    rospy 
    std_msgs 
) 

find_package(OpenCV 2.4.8 REQUIRED) 
find_package(Qt5 COMPONENTS Core Qml Quick REQUIRED) 


qt5_add_resources(RESOURCES qml.qrc) 

catkin_package(
    CATKIN_DEPENDS roscpp rospy std_msgs 
) 

include_directories(
    ${catkin_INCLUDE_DIRS} 
) 

add_executable(${PROJECT_NAME} ${RESOURCES} src/main.cpp src/draw_on_qimage.cpp src/provide_qpixmap_to_qml.cpp) 

qt5_use_modules(${PROJECT_NAME} Core Qml Quick) 

target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Qml Qt5::Quick ${OpenCV_LIBS}) 

Sposób uruchamiania go:

catkin_make -DCMAKE_PREFIX_PATH="/opt/Qt5.9.1/5.9.1/gcc_64/lib/" -DWITH_QT:BOOL=ON 

Tak mam pozyskiwane go.

Błędy:

Base path: /home/.../ros_workspace_test 
Source space: /home/.../ros_workspace_test/src 
Build space: /home/.../ros_workspace_test/build 
Devel space: /home/.../ros_workspace_test/devel 
Install space: /home/.../ros_workspace_test/install 
#### 
#### Running command: "cmake /home/.../ros_workspace_test/src -DCMAKE_PREFIX_PATH=/opt/Qt5.9.1/5.9.1/gcc_64/lib/ -DWITH_QT:BOOL=ON -DCATKIN_DEVEL_PREFIX=/home/.../ros_workspace_test/devel -DCMAKE_INSTALL_PREFIX=/home/.../ros_workspace_test/install -G Unix Makefiles" in "/home/.../ros_workspace_test/build" 
#### 
-- Using CATKIN_DEVEL_PREFIX: /home/.../ros_workspace_test/devel 
-- Using CMAKE_PREFIX_PATH: /opt/Qt5.9.1/5.9.1/gcc_64/lib/ 
-- Using PYTHON_EXECUTABLE: /usr/bin/python 
-- Using Debian Python package layout 
-- Using empy: /usr/bin/empy 
-- Using CATKIN_ENABLE_TESTING: ON 
-- Call enable_testing() 
-- Using CATKIN_TEST_RESULTS_DIR: /home/.../ros_workspace_test/build/test_results 
-- Found gtest sources under '/usr/src/gtest': gtests will be built 
-- Using Python nosetests: /usr/bin/nosetests-2.7 
-- catkin 0.6.19 
-- BUILD_SHARED_LIBS is on 
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
-- ~~ traversing 1 packages in topological order: 
-- ~~ - draw_on_images 
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
-- +++ processing catkin package: 'draw_on_images' 
-- ==> add_subdirectory(draw_on_images) 
-- Configuring done 
-- Generating done 
CMake Warning: 
    Manually-specified variables were not used by the project: 

    WITH_QT 


-- Build files have been written to: /home/.../ros_workspace_test/build 
#### 
#### Running command: "make -j4 -l4" in "/home/.../ros_workspace_test/build" 
#### 
[ 14%] Automoc for target draw_on_images 
[ 14%] Built target draw_on_images_automoc 
Linking CXX executable /home/.../ros_workspace_test/devel/lib/draw_on_images/draw_on_images 
CMakeFiles/draw_on_images.dir/src/main.cpp.o: In function `int qmlRegisterType<Draw_on_qimage>(char const*, int, int, char const*)': 
main.cpp:(.text._Z15qmlRegisterTypeI14Draw_on_qimageEiPKciiS2_[_Z15qmlRegisterTypeI14Draw_on_qimageEiPKciiS2_]+0x38): undefined reference to `Draw_on_qimage::staticMetaObject' 
main.cpp:(.text._Z15qmlRegisterTypeI14Draw_on_qimageEiPKciiS2_[_Z15qmlRegisterTypeI14Draw_on_qimageEiPKciiS2_]+0x1b6): undefined reference to `Draw_on_qimage::staticMetaObject' 
CMakeFiles/draw_on_images.dir/src/main.cpp.o: In function `Draw_on_qimage::~Draw_on_qimage()': 
main.cpp:(.text._ZN14Draw_on_qimageD2Ev[_ZN14Draw_on_qimageD5Ev]+0x13): undefined reference to `vtable for Draw_on_qimage' 
main.cpp:(.text._ZN14Draw_on_qimageD2Ev[_ZN14Draw_on_qimageD5Ev]+0x25): undefined reference to `vtable for Draw_on_qimage' 
CMakeFiles/draw_on_images.dir/src/main.cpp.o: In function `QMetaTypeIdQObject<Draw_on_qimage*, true>::qt_metatype_id()': 
main.cpp:(.text._ZN18QMetaTypeIdQObjectIP14Draw_on_qimageLb1EE14qt_metatype_idEv[_ZN18QMetaTypeIdQObjectIP14Draw_on_qimageLb1EE14qt_metatype_idEv]+0x2c): undefined reference to `Draw_on_qimage::staticMetaObject' 
CMakeFiles/draw_on_images.dir/src/main.cpp.o: In function `QtPrivate::MetaObjectForType<Draw_on_qimage*, true>::value()': 
main.cpp:(.text._ZN9QtPrivate17MetaObjectForTypeIP14Draw_on_qimageLb1EE5valueEv[_ZN9QtPrivate17MetaObjectForTypeIP14Draw_on_qimageLb1EE5valueEv]+0x7): undefined reference to `Draw_on_qimage::staticMetaObject' 
CMakeFiles/draw_on_images.dir/src/main.cpp.o:(.data.rel.ro._ZTVN11QQmlPrivate11QQmlElementI14Draw_on_qimageEE[_ZTVN11QQmlPrivate11QQmlElementI14Draw_on_qimageEE]+0x10): undefined reference to `Draw_on_qimage::metaObject() const' 
CMakeFiles/draw_on_images.dir/src/main.cpp.o:(.data.rel.ro._ZTVN11QQmlPrivate11QQmlElementI14Draw_on_qimageEE[_ZTVN11QQmlPrivate11QQmlElementI14Draw_on_qimageEE]+0x18): undefined reference to `Draw_on_qimage::qt_metacast(char const*)' 
CMakeFiles/draw_on_images.dir/src/main.cpp.o:(.data.rel.ro._ZTVN11QQmlPrivate11QQmlElementI14Draw_on_qimageEE[_ZTVN11QQmlPrivate11QQmlElementI14Draw_on_qimageEE]+0x20): undefined reference to `Draw_on_qimage::qt_metacall(QMetaObject::Call, int, void**)' 
CMakeFiles/draw_on_images.dir/src/main.cpp.o:(.data.rel.ro._ZTIN11QQmlPrivate11QQmlElementI14Draw_on_qimageEE[_ZTIN11QQmlPrivate11QQmlElementI14Draw_on_qimageEE]+0x10): undefined reference to `typeinfo for Draw_on_qimage' 
CMakeFiles/draw_on_images.dir/src/main.cpp.o: In function `Provide_QPixmap_to_QML::~Provide_QPixmap_to_QML()': 
main.cpp:(.text._ZN22Provide_QPixmap_to_QMLD2Ev[_ZN22Provide_QPixmap_to_QMLD5Ev]+0x13): undefined reference to `vtable for Provide_QPixmap_to_QML' 
main.cpp:(.text._ZN22Provide_QPixmap_to_QMLD2Ev[_ZN22Provide_QPixmap_to_QMLD5Ev]+0x25): undefined reference to `vtable for Provide_QPixmap_to_QML' 
CMakeFiles/draw_on_images.dir/src/draw_on_qimage.cpp.o: In function `Draw_on_qimage::Draw_on_qimage(QQuickPaintedItem*)': 
draw_on_qimage.cpp:(.text+0x4b): undefined reference to `vtable for Draw_on_qimage' 
draw_on_qimage.cpp:(.text+0x5d): undefined reference to `vtable for Draw_on_qimage' 
CMakeFiles/draw_on_images.dir/src/provide_qpixmap_to_qml.cpp.o: In function `Provide_QPixmap_to_QML::Provide_QPixmap_to_QML()': 
provide_qpixmap_to_qml.cpp:(.text+0x52): undefined reference to `vtable for Provide_QPixmap_to_QML' 
provide_qpixmap_to_qml.cpp:(.text+0x64): undefined reference to `vtable for Provide_QPixmap_to_QML' 
collect2: error: ld returned 1 exit status 
make[2]: *** [/home/.../ros_workspace_test/devel/lib/draw_on_images/draw_on_images] Error 1 
make[1]: *** [draw_on_images/CMakeFiles/draw_on_images.dir/all] Error 2 
make: *** [all] Error 2 
Invoking "make -j4 -l4" failed 

Jak połączyć Qt 5.9 w ROS?

używam Ubuntu 14.

+1

Coś nie tak z nagłówkiem i/lub plikami źródłowymi, które zawierają definicję klasy 'Draw_on_qimage'. Możliwe, że 'CMAKE_AUTOMOC' po prostu ich nie przetwarza (zobacz [docs] (https://cmake.org/cmake/help/latest/prop_tgt/AUTOMOC.html#prop_tgt:AUTOMOC) na temat tego, co to ustawienie właściwie robi). – Tsyvarev

+0

Zacznę od pominięcia 'qt5_use_modules', które jest przestarzałe i niepotrzebne, ponieważ nazywasz również' target_link_libraries'. – oLen

+0

Proponuję wyświetlać szczegółowe wyniki polecenia 'make', aby zobaczyć więcej informacji na temat wykonywania mocy. Powinieneś wtedy zobaczyć coś w rodzaju 'Generating moc source moc_Draw_on_qimage.cpp', a następnie'/path/to/moc -I [...] -D [...] -o /path/to/moc_Draw_on_qimage.cpp/path/do/Draw_on_qimage.h'. Czy to widzisz? Może dodanie 'draw_on_qimage.h' do' add_executable' również może pomóc. – oLen

Odpowiedz

1

rozwiązanie było dodać pliki nagłówkowe do add_executable w CMakeLists.txt:

add_executable(${PROJECT_NAME} ${RESOURCES} 
           src/main.cpp 
           include/draw_on_images/draw_on_qimage.h src/draw_on_qimage.cpp 
           include/draw_on_images/provide_qpixmap_to_qml.h src/provide_qpixmap_to_qml.cpp) 
1

Domyślam się, że AUTOMOC CUpewnij zawodzi w tym przypadku. Zobacz dokumentację tutaj https://cmake.org/cmake/help/v3.0/prop_tgt/AUTOMOC.html Potwierdza, że ​​plik nagłówkowy klasy Draw_on_qimage jest podobnie nazwany jako plik źródłowy i można go zlokalizować za pomocą CMake.

Można uniknąć AUTOMOC ręcznie uruchomiony MOC na nagłówek dla swojej klasy QObject pochodzący jak ten

QT5_WRAP_CPP(MOC_SOURCES <path of header file of your class Draw_on_qimage>) 

add_executable(${PROJECT_NAME} ${RESOURCES} src/main.cpp src/draw_on_qimage.cpp ${MOC_SOURCES} src/provide_qpixmap_to_qml.cpp