2013-11-26 43 views
1

嗨,亲爱的我正在使用Ubuntu 12.10和ros hydro我想在ros中使用Qt库。于是我尝试用简单的图书,如“QDebug”我写这个程序,CMake的如何在ros中使用Qt库

#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的链接,告诉我如何做到这一点?

回答

1

这看起来像一个错字:

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

使双方qt_test,或两者first_test。

+0

我不明白你在说什么。你能解释更多吗? 谢谢 – hamid

+0

您通知cmake您的可执行文件名为'first_test',然后您要求cmake将'qt_test'与$ {QT_LIBRARIES}链接。 cmake抱怨说它不知道什么是'qt_test' – Mali

+0

非常感谢:) – hamid