ROS与QtCreator:自动完成 [英] ROS with QtCreator: autocompletion
问题描述
我使用和像QtCreator一样编写和构建以 c ++ 编写的ROS项目
。 完成我自己的头文件不工作:eg #includeLineTracker.hh
构建项目完美。
更新2.0:使用QtCreator 3.6解决方案无法正常工作
更新1.0:找到解决方案,请参阅下页!
CMakeLists.txt看起来:
cmake_minimum_required(VERSION 2.8.3)
project(line_tracking)
SET(CMAKE_CXX_FLAGS$ {CMAKE_CXX_FLAGS} -std = c ++ 11)
find_package(catkin需要的组件
roscpp
tf
sensor_msgs
image_transport
cv_bridge
)
catkin_package()
include_directories(
include
$ {catkin_INCLUDE_DIRS}
$ {PROJECT_SOURCE_DIR}
)
add_executable($ {PROJECT_NAME}
src / line_tracking.cpp
src / EDLineDetector.cpp
src / LineTracker.cpp
)
target_link_libraries($ {PROJECT_NAME}
$ {catkin_LIBRARIES}
)
# - QT CREATOR STUFF ---
#添加项目子目录中的所有文件
#a dummy_target所以qtcreator可以访问所有文件
FILE(GLOB children $ { CMAKE_SOURCE_DIR} / *)
FOREACH(child $ {children})
IF(IS_DIRECTORY $ {child})
file(GLOB_RECURSE dir_files$ {child} / *)
LIST(APPEND extra_files $ {dir_files})
ENDIF()
ENDFOREACH()
add_custom_target(dummy _ $ {PROJECT_NAME} SOURCES $ {extra_files})
#
文件/包结构看起来像这样:
CMakeLists.txt
|
+ - src
|
+ - include
如何修改QtCreator找到的CMakeLists.txt
em>
当我使用QtCeator中catkin工作区的顶级CMakeLists.txt文件,并且我们在其包路径下包含头文件,如下所示: #include< packageName / include / headerFile.h>
自动完成正在工作,但构建不再工作。
更新1.0:
我发现一个解决方案是有效的:
所有具有头文件的(类)文件
,并将库链接到主文件,而不是将文件添加为可执行文件。我将其此处作为回答。但我不'知道为什么它是这样工作,而不是没有在图书馆的方式。任何解释?
更新2.0:
我刚刚升级到 QtCreator 3.6
和我的解决方案与库不工作了。
有人知道另一种解决方案吗?
更新:此解决方案不适用于QtCreator 3.6
我发现了一个解决我自己的问题的方法。没有那么多的乐趣,但无论如何,我花了很多时间与这个问题,所以这里的解决方案,这是希望对其他人有用:
自动完成对于您自己的类,在QtCreator 3.5.1中使用CMakeLists.txt:
- 使用所有类创建库:
ADD_LIBRARY(myFilesLib src / class1.cpp ...)
- 添加您的可执行文件(main函数):
add_executable $ {PROJECT_NAME} src / main.cpp)
- 将您的书架连结到您的可执行档:
target_link_libraries($ {PROJECT_NAME} myFilesLib) / code>
通过这种方式,在QtCreator中自动完成工作!
对于ROS(catkin),不要忘记链接 $ {catkin_LIBRARIES}
。
这里是整个CMakeLists.txt:
cmake_minimum_required(VERSION 2.8.3)
project(example_project)
SET(CMAKE_CXX_FLAGS$ {CMAKE_CXX_FLAGS} -std = c ++ 11)
find_package(catkin必需组件
roscpp
)
catkin_package()
include_directories(
include
$ {catkin_INCLUDE_DIRS}
$ {PROJECT_SOURCE_DIR}
)
#创建一个包含所有类的库
add_library(myFilesLib
src / class1.cpp
src / class2.cpp
src / class3.cpp
)
target_link_libraries(myFilesLib
$ {catkin_LIBRARIES}
)
#添加可执行文件
add_executable($ {PROJECT_NAME}
src / main。 cpp
)
#将库与您的类链接到可执行文件
target_link_libraries($ {PROJECT_NAME}
$ {catkin_LIBRARIES}
myFilesLib
)
我不知道为什么它只工作在图书馆的方式,加工。也许有人有解释?!
I'm using and like QtCreator to code and build my ROS projects written in c++.
Unfortunately the auto-completion for my own header files is not working: e.g. #include "LineTracker.hh"
Building the project works perfectly. And also the auto-completion for other external packages like ros or opencv is working.
Update 2.0: With QtCreator 3.6 the solution is not working
Update 1.0: Found a solution, see bottom!
Thats how my CMakeLists.txt looks:
cmake_minimum_required(VERSION 2.8.3)
project(line_tracking)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
find_package(catkin REQUIRED COMPONENTS
roscpp
tf
sensor_msgs
image_transport
cv_bridge
)
catkin_package()
include_directories(
include
${catkin_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}
)
add_executable(${PROJECT_NAME}
src/line_tracking.cpp
src/EDLineDetector.cpp
src/LineTracker.cpp
)
target_link_libraries(${PROJECT_NAME}
${catkin_LIBRARIES}
)
# --- QT CREATOR STUFF ---
#Add all files in subdirectories of the project in
# a dummy_target so qtcreator has access to all files
FILE(GLOB children ${CMAKE_SOURCE_DIR}/*)
FOREACH(child ${children})
IF(IS_DIRECTORY ${child})
file(GLOB_RECURSE dir_files "${child}/*")
LIST(APPEND extra_files ${dir_files})
ENDIF()
ENDFOREACH()
add_custom_target(dummy_${PROJECT_NAME} SOURCES ${extra_files})
#
The file/package structure looks standard like this:
CMakeLists.txt
|
+ -- src
|
+ -- include
How do I have to adapt my CMakeLists.txt that QtCreator finds my headers for autocompletion?
Thank you very much for your help!
Sidenote:
When I use the top CMakeLists.txt file of the catkin workspace in QtCeator and I include the header files under their package path like this: #include <packageName/include/headerFile.h>
the auto-completion is working but the build is not working anymore. So this is only a bad and not userfriendly hack to get auto-completion during coding.
Update 1.0:
I found a solution which is working:
I create a library from all the (class) files which have header files, and link the library to the main file, instead of adding the files as executables. I posted it here as answer.
But I don't know why it is working like this and not without the way over the library. Any explanations?
Update 2.0:
I just upgraded to QtCreator 3.6
and there my solution with the library in not working anymore.
Does anybody know another solution?!
Update: This solution does NOT work with QtCreator 3.6
I found a solution to my own question. Not so much fun, but anyway, I spent a lot of time with that issue so here the solution, which is hopefully useful for others:
Auto-completion with CMakeLists.txt in QtCreator 3.5.1 for your own classes:
- Create a library with all your classes:
ADD_LIBRARY(myFilesLib src/class1.cpp ...)
- Add your executable (main function):
add_executable(${PROJECT_NAME} src/main.cpp)
- Link your library to your executable:
target_link_libraries(${PROJECT_NAME} myFilesLib)
With this way over the library, auto-completion is working in QtCreator!
For ROS (catkin) don't forget to link the ${catkin_LIBRARIES}
.
Here the whole CMakeLists.txt:
cmake_minimum_required(VERSION 2.8.3)
project(example_project)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
find_package(catkin REQUIRED COMPONENTS
roscpp
)
catkin_package()
include_directories(
include
${catkin_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}
)
# Create a library with all your classes
add_library(myFilesLib
src/class1.cpp
src/class2.cpp
src/class3.cpp
)
target_link_libraries(myFilesLib
${catkin_LIBRARIES}
)
# add your executable
add_executable(${PROJECT_NAME}
src/main.cpp
)
# link the library with your classes to the executable
target_link_libraries(${PROJECT_NAME}
${catkin_LIBRARIES}
myFilesLib
)
I don't know why it is working only with the way over the library but it is working. Maybe somebody has an explanation?!
这篇关于ROS与QtCreator:自动完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!