Getting error : CMake can not determine linker language for target, even with set_target_properties in CmakeLists
Hi I am facing an error :
My cmakelists.txt file is as follows -
cmake_minimum_required(VERSION 3.0.2)
project(ros0xrobot CXX)
find_package(catkin REQUIRED COMPONENTS
geometry_msgs
roscpp
rospy
std_msgs
tf2
)
###################################
## catkin specific configuration ##
###################################
catkin_package(
INCLUDE_DIRS include
LIBRARIES ros0xrobot
CATKIN_DEPENDS geometry_msgs roscpp rospy std_msgs tf2
#DEPENDS system_lib
)
add_library(${PROJECT_NAME} /home/ril/catkin_ws/src/ros0xrobot/src/rosRobotcpplib.h
# /home/ril/catkin_ws/src/ros0xrobot/src/rosRobotNode.cpp
)
add_executable(${PROJECT_NAME}_node /home/ril/catkin_ws/src/ros0xrobot/src/rosRobotNode.cpp)
target_compile_options( ${PROJECT_NAME}_node PUBLIC -std=c++11 -fpermissive -w -Wall )
target_link_libraries(${PROJECT_NAME}_node ${catkin_LIBRARIES})
set_target_properties(${PROJECT_NAME}_node PROPERTIES LINKER_LANGUAGE CXX)
Please give some pointers. I have added the line below as per many sources, but still doesnt work.
set_target_properties(${PROJECT_NAME}_node PROPERTIES LINKER_LANGUAGE CXX)
thanks. System - Ubuntu Ros - Noetic Using Catkin build
UPDATE: 1. We tried having both .h and .cpp file in add_library, which didn't work. It gave the same error.
Asked by madangt on 2023-02-28 06:24:30 UTC
Comments
It's probably caused by:
C++ libraries cannot have only header files (
.h
) as their "sources".Also: for future questions: please remove all the comments from the
CMakeLists.txt
you post. It makes your post unnecessarily long and more difficult to read.I would also suggest to not use absolute paths to
.cpp
and/or.h
files like you do here.Asked by gvdhoorn on 2023-03-06 03:32:25 UTC
I tried having both .h and .cpp in add_library, but we get the same error that we listed. Also, I had relative paths earlier and the error showed that it was not able to track the package. So, I gave the absolute path. *: For sure, we did not want to keep the entire CMake in the problem, but we doubted if we missed some function or a line somewhere which remained commented.
Asked by madangt on 2023-03-06 04:07:43 UTC
To make it easier for others to help you, I'd advise you to update your original question text with the exact contents of the
CMakeLists.txt
which results in the problem you describe. Don't show "one of the versions which also doesn't work", and describe clearly what you've already tried (such as what you write in your comment).Do remove all of the commented lines.
Otherwise people here can only guess, and will likely suggest things you've already tried. That would just waste your time, and ours.
Asked by gvdhoorn on 2023-03-06 04:52:32 UTC
Took note of your advice, the question has been updated.
Asked by madangt on 2023-03-06 05:05:26 UTC