“CMake 错误:CMake 无法确定目标的链接器语言” 当我 catkin_make ROS 工作空间时出现错误
Posted
技术标签:
【中文标题】“CMake 错误:CMake 无法确定目标的链接器语言” 当我 catkin_make ROS 工作空间时出现错误【英文标题】:"CMake Error: CMake can not determine linker language for target" The errors appeared when I catkin_make a ROS working space 【发布时间】:2021-04-15 12:20:49 【问题描述】:当我 catkin_make 我的 ROS 工作空间时,它总是被错误完成:
CMake Error: CMake can not determine linker language for target: XX
CMake Error: Cannot determine link language for target "XX".
根据XX的信息,我发现错误可能位于其中一个ROS包中。包中有一个 CMakeList.txt 和一个 package.xml。 但我并不确切知道导致错误的原因,直到现在我还没有解决这个问题。下面我展示了这两个文件的确切代码。
CMakeList.txt
cmake_minimum_required(VERSION 3.0.2)
project(omnicopter_controller)
add_definitions(-std=c++11)
find_package(catkin REQUIRED COMPONENTS
geometry_msgs
mav_msgs
nav_msgs
sensor_msgs
cmake_modules
roscpp
rospy
std_msgs
)
find_package(Eigen3 REQUIRED)
catkin_package(
INCLUDE_DIRS include $Eigen3_INCLUDE_DIRS
LIBRARIES omnicopter_controller
CATKIN_DEPENDS geometry_msgs mav_msgs nav_msgs roscpp sensor_msgs
DEPENDS Eigen3
)
include_directories(
include
$catkin_INCLUDE_DIRS
$Eigen3_INCLUDE_DIRS
)
add_executable(omnicopter_position_controller_pub
src/omnicopter_position_controller_pub.cpp
)
add_dependencies(omnicopter_position_controller_pub $$PROJECT_NAME_EXPORTED_TARGETS $catkin_EXPORTED_TARGETS)
target_link_libraries(omnicopter_position_controller_pub
$catkin_LIBRARIES
)
add_executable(omnicopter_position_controller_sub
src/omnicopter_position_controller_sub.cpp
)
add_dependencies(omnicopter_position_controller_sub $$PROJECT_NAME_EXPORTED_TARGETS $catkin_EXPORTED_TARGETS)
target_link_libraries(omnicopter_position_controller_sub
$catkin_LIBRARIES
)
add_executable(omnicopter_attitude_controller_pub
src/omnicopter_attitude_controller_pub.cpp
)
add_dependencies(omnicopter_attitude_controller_pub $$PROJECT_NAME_EXPORTED_TARGETS $catkin_EXPORTED_TARGETS)
target_link_libraries(omnicopter_attitude_controller_pub
$catkin_LIBRARIES
)
add_executable(omnicopter_attitude_controller_sub
src/omnicopter_attitude_controller_sub.cpp
)
add_dependencies(omnicopter_attitude_controller_sub $$PROJECT_NAME_EXPORTED_TARGETS $catkin_EXPORTED_TARGETS)
target_link_libraries(omnicopter_attitude_controller_sub
$catkin_LIBRARIES
)
add_executable(omnicopter_body_angular_velocity_controller_pub
src/omnicopter_body_angular_velocity_controller_pub.cpp
)
add_dependencies(omnicopter_body_angular_velocity_controller_pub $$PROJECT_NAME_EXPORTED_TARGETS $catkin_EXPORTED_TARGETS)
target_link_libraries(omnicopter_body_angular_velocity_controller_pub
$catkin_LIBRARIES
)
add_executable(omnicopter_body_angular_velocity_controller_sub
src/omnicopter_body_angular_velocity_controller_sub.cpp
)
add_dependencies(omnicopter_body_angular_velocity_controller_sub $$PROJECT_NAME_EXPORTED_TARGETS $catkin_EXPORTED_TARGETS)
target_link_libraries(omnicopter_body_angular_velocity_controller_sub
$catkin_LIBRARIES
)
add_executable(omnicopter_control_allocator_pub
src/omnicopter_control_allocator_pub.cpp
)
add_dependencies(omnicopter_control_allocator_pub $$PROJECT_NAME_EXPORTED_TARGETS $catkin_EXPORTED_TARGETS)
target_link_libraries(omnicopter_control_allocator_pub
$catkin_LIBRARIES
)
add_executable(omnicopter_control_allocator_sub
src/omnicopter_control_allocator_sub.cpp
)
add_dependencies(omnicopter_control_allocator_sub $$PROJECT_NAME_EXPORTED_TARGETS $catkin_EXPORTED_TARGETS)
target_link_libraries(omnicopter_control_allocator_sub
$catkin_LIBRARIES
)
add_library(omnicopter_position_controller
include/omnicopter_controller/omnicopter_position_controller.h
)
add_dependencies(omnicopter_position_controller $$PROJECT_NAME_EXPORTED_TARGETS $catkin_EXPORTED_TARGETS)
target_link_libraries(omnicopter_position_controller
$catkin_LIBRARIES
)
add_library(omnicopter_attitude_controller
include/omnicopter_controller/omnicopter_attitude_controller.h
)
add_dependencies(omnicopter_attitude_controller $$PROJECT_NAME_EXPORTED_TARGETS $catkin_EXPORTED_TARGETS)
target_link_libraries(omnicopter_attitude_controller
$catkin_LIBRARIES
)
add_library(omnicopter_body_angular_velocity_controller
include/omnicopter_controller/omnicopter_body_angular_velocity_controller.h
)
add_dependencies(omnicopter_body_angular_velocity_controller $$PROJECT_NAME_EXPORTED_TARGETS $catkin_EXPORTED_TARGETS)
target_link_libraries(omnicopter_body_angular_velocity_controller
$catkin_LIBRARIES
)
add_library(omnicopter_control_allocator
include/omnicopter_controller/omnicopter_control_allocator.h
)
add_dependencies(omnicopter_control_allocator $$PROJECT_NAME_EXPORTED_TARGETS $catkin_EXPORTED_TARGETS)
target_link_libraries(omnicopter_control_allocator
$catkin_LIBRARIES
)
package.xml
<?xml version="1.0"?>
<package format="2">
<name>omnicopter_controller</name>
<version>0.0.0</version>
<description>The omnicopter_controller package</description>
<maintainer email="hdl@todo.todo">hdl</maintainer>
<author>Dingliang Huang</author>
<license>TODO</license>
<buildtool_depend>catkin</buildtool_depend>
<depend>rospy</depend>
<depend>std_msgs</depend>
<depend>cmake_modules</depend>
<depend>dynamic_reconfigure</depend>
<depend>geometry_msgs</depend>
<depend>mav_msgs</depend>
<depend>nav_msgs</depend>
<depend>roscpp</depend>
<depend>sensor_msgs</depend>
</package>
下面我显示了确切的错误。
错误:
CMake Error: CMake can not determine linker language for target: omnicopter_position_controller
CMake Error: Cannot determine link language for target "omnicopter_position_controller".
CMake Error: CMake can not determine linker language for target: omnicopter_attitude_controller
CMake Error: Cannot determine link language for target "omnicopter_attitude_controller".
CMake Error: CMake can not determine linker language for target: omnicopter_control_allocator
CMake Error: Cannot determine link language for target "omnicopter_control_allocator".
CMake Error: CMake can not determine linker language for target: omnicopter_body_angular_velocity_controller
CMake Error: Cannot determine link language for target "omnicopter_body_angular_velocity_controller".
我希望有人可以帮助我解决这些错误。我会很感激的。
【问题讨论】:
你为什么要制作没有源文件的库? 感谢 cmets。我已经解决了这些问题。这些错误是由于在每个 add_library() 之后缺少 set_target_properties(XX PROPERTIES LINKER_LANGUAGE C++) 造成的 【参考方案1】:我已经解决了这些问题。这些错误是由于在每个 add_library() 之后缺少 set_target_properties(XX PROPERTIES LINKER_LANGUAGE C++) 造成的。
【讨论】:
以上是关于“CMake 错误:CMake 无法确定目标的链接器语言” 当我 catkin_make ROS 工作空间时出现错误的主要内容,如果未能解决你的问题,请参考以下文章