add_subdirectory: Cmake Error
Error Message:
-- +++ processing catkin package: 'ir_bx_lab'
-- ==> add_subdirectory(ir_bx_lab)
CMake Error at /opt/ros/noetic/share/catkin/cmake/catkin_workspace.cmake:121 (add_subdirectory):
The source directory
/home/isharm2/catkin_ws/src/ir_bx_lab
does not contain a CMakeLists.txt file.
Call Stack (most recent call first):
CMakeLists.txt:69 (catkin_workspace)
When I searched, I found this on Google, But not sure, How to use that?
add_subdirectory(source_dir [binary_dir] [EXCLUDE_FROM_ALL])
I haven't had to do something like this for any other packages, for the packages I have worked with. Can you help me with the same?
Thanks in Advance.
Edit: After fixing the CMakeLists.txt absent error, I still get the same error.
Here is My CMakeLists.txt
# toplevel CMakeLists.txt for a catkin workspace
# catkin/cmake/toplevel.cmake
cmake_minimum_required(VERSION 3.0.2)
project(Project)
set(CATKIN_TOPLEVEL TRUE)
# search for catkin within the workspace
set(_cmd "catkin_find_pkg" "catkin" "${CMAKE_SOURCE_DIR}")
execute_process(COMMAND ${_cmd}
RESULT_VARIABLE _res
OUTPUT_VARIABLE _out
ERROR_VARIABLE _err
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE
)
if(NOT _res EQUAL 0 AND NOT _res EQUAL 2)
# searching fot catkin resulted in an error
string(REPLACE ";" " " _cmd_str "${_cmd}")
message(FATAL_ERROR "Search for 'catkin' in workspace failed (${_cmd_str}): ${_err}")
endif()
# include catkin from workspace or via find_package()
if(_res EQUAL 0)
set(catkin_EXTRAS_DIR "${CMAKE_SOURCE_DIR}/${_out}/cmake")
# include all.cmake without add_subdirectory to let it operate in same scope
include(${catkin_EXTRAS_DIR}/all.cmake NO_POLICY_SCOPE)
add_subdirectory()
else()
# use either CMAKE_PREFIX_PATH explicitly passed to CMake as a command line argument
# or CMAKE_PREFIX_PATH from the environment
if(NOT DEFINED CMAKE_PREFIX_PATH)
if(NOT "$ENV{CMAKE_PREFIX_PATH}" STREQUAL "")
if(NOT WIN32)
string(REPLACE ":" ";" CMAKE_PREFIX_PATH $ENV{CMAKE_PREFIX_PATH})
else()
set(CMAKE_PREFIX_PATH $ENV{CMAKE_PREFIX_PATH})
endif()
endif()
endif()
# list of catkin workspaces
set(catkin_search_path "")
foreach(path ${CMAKE_PREFIX_PATH})
if(EXISTS "${path}/.catkin")
list(FIND catkin_search_path ${path} _index)
if(_index EQUAL -1)
list(APPEND catkin_search_path ${path})
endif()
endif()
endforeach()
# search for catkin in all workspaces
set(CATKIN_TOPLEVEL_FIND_PACKAGE TRUE)
find_package(catkin QUIET
NO_POLICY_SCOPE
PATHS ${catkin_search_path}
NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
unset(CATKIN_TOPLEVEL_FIND_PACKAGE)
if(NOT catkin_FOUND)
message(FATAL_ERROR "find_package(catkin) failed. catkin was neither found in the workspace nor in the CMAKE_PREFIX_PATH. One reason may be that no ROS setup.sh was sourced before.")
endif()
endif()
catkin_workspace()
Asked by ishaniis on 2021-10-20 16:26:48 UTC
Answers
The error occurs because there is no
Create CMakeLists.txt
in /home/isharm2/catkin_ws/src/ir_bx_lab
and you should be able to proceed.
Usually, when you create a ROS package, you use catkin_create_pkg
to create the base of CMakeLists.txt
as follows.
catkin_create_pkg ir_bx_lab std_msgs rospy roscpp
See : http://wiki.ros.org/ROS/Tutorials/CreatingPackage
Asked by miura on 2021-10-20 16:37:03 UTC
Comments
@miura I fixed the CMakeLists.txt error. But for this add_subdirectory error, I am unable to solve.
-- ==> add_subdirectory(.)
CMake Error at /opt/ros/noetic/share/catkin/cmake/catkin_workspace.cmake:121 (add_subdirectory):
add_subdirectory not given a binary directory but the given source
directory "/home/isharm2/catkin_ws/src/ir_bx_lab" is not a subdirectory of
"/home/isharm2/catkin_ws/src/ir_bx_lab". When specifying an out-of-tree
source a binary directory must be explicitly specified.
Call Stack (most recent call first):
ir_bx_lab/CMakeLists.txt:69 (catkin_workspace)
Asked by ishaniis on 2021-10-20 17:15:02 UTC
Comments
this is not your
CMakeLists.txt
, but the one in thesrc
space of your workspace. That's a default file, and you should not touch it, nor change it.Asked by gvdhoorn on 2021-10-21 03:43:22 UTC
@gvdhoorn So, What will you suggest to solve this particular issue?
Asked by ishaniis on 2021-10-21 11:48:43 UTC
Is
ir_bx_lab
a ROS package? Does it have apackage.xml
? If it does, but their_bx_lab
directory does not contain aCMakeLists.txt
, you'll likely see this error. ROS 1 packages can not not have aCMakeLists.txt
.In any case: the problem is with your package, not with
/home/isharm2/catkin_ws/src/CMakeLists.txt
(as that's very unlikely to be broken).Asked by gvdhoorn on 2021-10-21 11:53:50 UTC
Got it. Thanks for always helping out. It's the ROS package manufacturer gave us. I believe, my journey to learn ROS (and many of us like me) is incomplete without your prompt support here. Thank you!
Asked by ishaniis on 2021-10-21 12:08:02 UTC
Well it's something to check, so please verify what I wrote is correct.
If it isn't, something else might be wrong and that would need to be further diagnosed.
Asked by gvdhoorn on 2021-10-21 12:19:21 UTC
I guess during the transfer the package might be corrupted. I'll remove the current package from the workspace and will try again with it.
But ROS1 packages cant have their CMakeLists.txt ??
Asked by ishaniis on 2021-10-21 12:27:02 UTC
I don't understand what you mean by this.
Perhaps my use of a double negative confused you. I wrote:
by which I meant: you cannot have a ROS 1 package without a
CMakeLists.txt
.catkin_make
would not know how to deal with it.Asked by gvdhoorn on 2021-10-21 12:36:11 UTC
Ah! Got it!
Asked by ishaniis on 2021-10-21 12:43:08 UTC