亲爱的,我正在使用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如何做到这一点?
答案 0 :(得分:1)
这看起来像是一个错字:
rosbuild_add_executable(first_test src/first_test.cpp)
target_link_libraries(qt_test ${QT_LIBRARIES})
同时制作qt_test或同时制作first_test。