g++ 11.4 ubuntu 22.04 中的 ros2 冒号构建错误

问题描述 投票:0回答:1

使用 ros2 构建代码并看到此错误 是不是有什么东西没安装? 或者我在 cmakelist 中犯了错误? 我想在 ubuntu 22.04 中使用 ros2 创建一个套接字

$ colcon build
Starting >>> socket  
--- stderr: socket                             
/usr/bin/ld: cannot find -lsocket: No such file or directory
collect2: error: ld returned 1 exit status
gmake[2]: *** [CMakeFiles/socket_server_node.dir/build.make:151: socket_server_node] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:165: CMakeFiles/socket_server_node.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2
---
Failed   <<< socket [0.22s, exited with code 2]

c++ sockets ubuntu ros2 cmakelists-options
1个回答
0
投票

这是我的 CMAKELIST


cmake_minimum_required(VERSION 3.8)
project(socket)

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)
find_package(std_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)

# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)

set(dependencies
  rclcpp
  std_msgs
  sensor_msgs
)

set(SOURCES
  src/netsockserver.cpp
)
# add_library(netsock src/netsock.cpp)
add_library(netsockserver src/netsockserver.cpp)

# add_library(time src/time.cpp)


include_directories(
    include)


add_executable(socket_server_node src/socket_server_node.cpp)
target_link_libraries(socket_server_node
                      ${PROJECT_NAME}
                      ${catkin_LIBRARIES}
                      )
ament_target_dependencies(socket_server_node rclcpp)
ament_target_dependencies(netsockserver rclcpp)
install(TARGETS
    socket_server_node
    DESTINATION lib/${PROJECT_NAME}
)


# Install the library
install(TARGETS netsockserver
  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib
  RUNTIME DESTINATION bin
  INCLUDES DESTINATION include
)

# install this package
install(DIRECTORY
    include/
    DESTINATION include/
)

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()
© www.soinside.com 2019 - 2024. All rights reserved.