踩坑总结
1、project(485_release)不符合命名规范,会有warning,改为project(motor)就好了,经证实加数字有影响,下划线没有影响,注意package.xml也要修改 name为motor
2、添加自定义头文件要显示完整路径include_directories(/home/hahalim/ros2_ws/src/485_release/include)
3、添加链接库的格式为link_directories(/home/hahalim/ros2_ws/src/485_release/lib}),target_link_libraries(check_c libUnitree_motor_SDK_Linux64.so )
target_link_libraries(check_cpp libUnitree_motor_SDK_Linux64.so )顺序必须在add_executable()之后,check_c和check_cpp是可执行文件的名称
CMakeList.txt
cmake_minimum_required(VERSION 3.5)
project(motor)
set(LIBCONFIG_INC_DIR "/home/hahalim/ros2_ws/src/485_release/include")
set(LIBCONFIG_LINK_DIR "/home/hahalim/ros2_ws/src/485_release/lib")
include_directories(${LIBCONFIG_INC_DIR})
link_directories(${LIBCONFIG_LINK_DIR})
# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()
# 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(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
add_executable(check_c src/check.c)
ament_target_dependencies(check_c rclcpp std_msgs)
add_executable(check_cpp src/check.cpp)
ament_target_dependencies(check_cpp rclcpp std_msgs)
target_link_libraries(check_c libUnitree_motor_SDK_Linux64.so )
target_link_libraries(check_cpp libUnitree_motor_SDK_Linux64.so )
install(TARGETS
check_c
check_cpp
DESTINATION lib/${PROJECT_NAME})
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
set(ament_cmake_copyright_FOUND TRUE)
set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()
ament_package()
package.xml
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="2">
<name>motor</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="hahalim@todo.todo">hahalim</maintainer>
<license>TODO: License declaration</license>
<buildtool_depend>ament_cmake</buildtool_depend>
<depend>rclcpp</depend>
<depend>std_msgs</depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
<export>
<build_type>ament_cmake</build_type>
</export>
</package>