【问题标题】:How to use Qt libraries in ros如何在ros中使用Qt库
【发布时间】:2013-11-26 10:22:19
【问题描述】:

嗨,亲爱的,我正在使用 Ubuntu 12.10 和 ros hydro 我想在 ros 中使用 Qt 库。所以我尝试使用像“QDebug”这样的简单库,我编写了这个程序和 Cmake

#include "QDebug"
#include "ros/ros.h"

int main(int argc, char** argv)
{
  ros::init(argc, argv, "Qt_test");
  qDebug()<<"Hello world";
    return 0;
}

和cmake文件:

cmake_minimum_required(VERSION 2.4.6)
find_package(Qt4 COMPONENTS QtCore QtGui)
INCLUDE(${QT_USE_FILE})
ADD_DEFINITIONS(${QT_DEFINITIONS})

include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)

# Set the build type.  Options are:
#  Coverage       : w/ debug symbols, w/o optimization, w/ code-coverage
#  Debug          : w/ debug symbols, w/o optimization
#  Release        : w/o debug symbols, w/ optimization
#  RelWithDebInfo : w/ debug symbols, w/ optimization
#  MinSizeRel     : w/o debug symbols, w/ optimization, stripped binaries
#set(ROS_BUILD_TYPE RelWithDebInfo)

rosbuild_init()

#set the default path for built executables to the "bin" directory
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
#set the default path for built libraries to the "lib" directory
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

#uncomment if you have defined messages
#rosbuild_genmsg()
#uncomment if you have defined services
#rosbuild_gensrv()

#common commands for building c++ executables and libraries
#rosbuild_add_library(${PROJECT_NAME} src/example.cpp)
#target_link_libraries(${PROJECT_NAME} another_library)
#rosbuild_add_boost_directories()
#rosbuild_link_boost(${PROJECT_NAME} thread)
rosbuild_add_executable(first_test src/first_test.cpp)
target_link_libraries(qt_test ${QT_LIBRARIES})

但是当我尝试使用 rosmake 制作我的包时发生了这个错误。

mkdir -p bin cd build && cmake -Wdev -DCMAKE_TOOLCHAIN_FILE=/opt/ros/hydro/share/ros/core/rosbuild/rostoolchain.cmake
.. [rosbuild] Building package qt_test 
-- Using CATKIN_DEVEL_PREFIX:/home/hamid/working_space/qt_test/build/devel 
-- Using CMAKE_PREFIX_PATH:/opt/ros/hydro 
-- This workspace overlays:/opt/ros/hydro 
-- Using Debian Python package layout 
-- Using CATKIN_ENABLE_TESTING: ON 
-- Skip enable_testing() for dry packages
-- Using CATKIN_TEST_RESULTS_DIR: /home/hamid/working_space/qt_test/build/test_results
-- Found gtest
sources under '/usr/src/gtest': gtests will be built -- catkin 0.5.77
[rosbuild] 
Including /opt/ros/hydro/share/roslisp/rosbuild/roslisp.cmake [rosbuild]
Including /opt/ros/hydro/share/roscpp/rosbuild/roscpp.cmake
[rosbuild] Including /opt/ros/hydro/share/rospy/rosbuild/rospy.cmake

CMake Error at CMakeLists.txt:34 (target_link_libraries): Cannot
specify link libraries for target "qt_test" which is not built by
this project.

-- Configuring incomplete, errors occurred!

有人帮助我吗?我对 cmake 有一点了解。谁能给我 cmake 的链接,告诉我如何做到这一点?

【问题讨论】:

    标签: c++ qt ubuntu cmake ros


    【解决方案1】:

    这看起来像是一个错字:

    rosbuild_add_executable(first_test src/first_test.cpp)
    target_link_libraries(qt_test ${QT_LIBRARIES})
    

    同时制作 qt_test,或同时制作 first_test。

    【讨论】:

    • 我不明白你在说什么。你能解释更多吗?谢谢
    • 您通知 cmake 您的可执行文件名为 first_test,然后您要求 cmake 将 qt_test 与 ${QT_LIBRARIES} 链接。 cmake 抱怨不知道qt_test是什么@
    猜你喜欢
    • 2018-05-23
    • 1970-01-01
    • 1970-01-01
    • 2021-07-26
    • 2017-10-16
    • 2015-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多