我一直没有得到这样的文件或目录。当我尝试将其添加到我的源文件#include“rclcpp/rclcpp.hpp”时。我不明白的是 VC 说没有这样的文件,但是当我从这个库中编写一些函数时,它会自动完成它们。
这是错误。
开始构建... 致命错误:rclcpp/rclcpp.hpp:没有这样的文件或目录 1 | #include“rclcpp/rclcpp.hpp” | ^~~~~~~~~~~~~~~~~~~
这里还有 cmake 和 .json 文件。
.json where I added library path.
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/opt/ros/humble/include/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++17",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
cmake file.
cmake_minimum_required(VERSION 3.8)
project(my_cpp_pkg)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# comment the line when a copyright and license is added to all source files
set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# comment the line when this package is in a git repo and when
# a copyright and license is added to all source files
set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()
ament_package()
The source code.
#include "rclcpp/rclcpp.hpp"
int main(int argc, char **argv){
rclcpp::init(argc, argv);
rclcpp::shutdown();
return 0;
}
你也构建失败了吗?我注意到您尚未将 .cpp 文件添加为目标,并且 rclcpp 未链接到它。
您可以检查这个示例,并将您的 *.cpp 文件名替换为此。
更新:我将代码粘贴到此处,以防链接不起作用。
cmake_minimum_required(VERSION 3.5)
project(demo_nodes_cpp_native)
# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_components REQUIRED)
find_package(rmw REQUIRED)
find_package(std_msgs REQUIRED)
find_package(rmw_fastrtps_cpp QUIET)
include_directories(include)
if(rmw_fastrtps_cpp_FOUND)
add_library(talker_native SHARED
src/talker.cpp)
target_compile_definitions(talker_native
PRIVATE "DEMO_NODES_CPP_NATIVE_BUILDING_DLL")
ament_target_dependencies(talker_native
"rclcpp"
"std_msgs"
"rclcpp_components"
"rmw_fastrtps_cpp")
rclcpp_components_register_node(talker_native PLUGIN "demo_nodes_cpp_native::Talker" EXECUTABLE talker)
install(TARGETS
talker_native
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
find_package(ament_cmake_pytest REQUIRED)
find_package(launch_testing_ament_cmake REQUIRED)
set(tutorial_executables "talker")
set(DEMO_NODES_CPP_EXPECTED_OUTPUT "")
foreach(executable ${tutorial_executables})
list(APPEND DEMO_NODES_CPP_EXPECTED_OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/test/${executable}")
endforeach()
set(DEMO_NODES_CPP_EXECUTABLE "")
foreach(executable ${tutorial_executables})
list(APPEND DEMO_NODES_CPP_EXECUTABLE "$<TARGET_FILE:${executable}>")
endforeach()
string(REPLACE ";" "_" exe_list_underscore "${tutorial_executables}")
configure_file(
test/test_executables_tutorial.py.in
test_${exe_list_underscore}.py.configured
@ONLY
)
file(GENERATE
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/test_${exe_list_underscore}_$<CONFIG>.py"
INPUT "${CMAKE_CURRENT_BINARY_DIR}/test_${exe_list_underscore}.py.configured"
)
add_launch_test(
"${CMAKE_CURRENT_BINARY_DIR}/test_${exe_list_underscore}_$<CONFIG>.py"
TARGET test_tutorial_${exe_list_underscore}
TIMEOUT 30
ENV
RCL_ASSERT_RMW_ID_MATCHES=rmw_fastrtps_cpp
RMW_IMPLEMENTATION=rmw_fastrtps_cpp
)
foreach(executable ${tutorial_executables})
set_property(
TEST test_tutorial_${exe_list_underscore}
APPEND PROPERTY DEPENDS ${executable})
endforeach()
endif()
endif()
ament_package()
我认为从你的 CMakefile 中,你可能会忘记声明..
包含文件位于 /opt/ros/humble/include/rclcpp/rclcpp 如果您在 ubuntu 上使用简单的 LTS