/home/lilabws001/catkin_pkg/devel/setup.bash: No such file or directory bash: /home/lilabws001/catkin_ws/devel/setup.bash: No such file or directory bash: /home/lilabws001/catkin_ws/devel/setup.bash: No such file or directory --: command not found --: command not found --: command not found --: command not found --: command not found --: command not found --: command not found --: command not found --: command not found --: command not found --: command not found --: command not found --: command not found --: command not found --: command not found --: command not found bash: /home/lilabws001/.bashrc: line 140: syntax error near unexpected token `(' bash: /home/lilabws001/.bashrc: line 140: `-- ==> add_subdirectory(realsense-ros/realsense2_description)'
时间: 2025-07-29 15:05:24 浏览: 6
### ROS Catkin Workspace Setup 问题排查
在使用 ROS(Robot Operating System)时,`catkin` 是其核心构建系统之一。如果在构建或运行过程中遇到 `setup.bash not found` 或 `bashrc syntax error near unexpected token` 错误,通常与工作空间构建失败或环境变量配置不当有关。
#### `setup.bash not found` 错误排查
该错误通常表示 `catkin_make` 或 `catkin_make_isolated` 未能成功构建工作空间,导致 `devel/setup.bash` 文件未生成。构建失败可能由以下原因引起:
- **CMakeLists.txt 或 package.xml 文件配置错误**:ROS 包的 `CMakeLists.txt` 和 `package.xml` 文件必须正确声明依赖项和构建参数。如果文件中存在语法错误或路径引用错误,会导致构建失败。
- **未正确初始化工作空间**:在执行 `catkin_make` 之前,应确保 `src` 目录中包含有效的 ROS 包,并且工作空间结构完整。
- **构建命令执行失败**:使用 `catkin_make` 时,必须在工作空间根目录(如 `~/catkin_ws`)下执行,否则可能找不到 `CMakeLists.txt` 文件 [^1]。
可以尝试以下命令重新构建工作空间:
```bash
cd ~/catkin_ws
catkin_make
source devel/setup.bash
```
如果仍然无法生成 `setup.bash`,则需要检查构建日志,定位具体失败的包或错误信息。
#### `bashrc syntax error near unexpected token` 错误排查
该错误通常出现在 `.bashrc` 文件中添加了不合法的 `source` 命令,或者路径拼写错误。例如,以下错误写法会导致语法错误:
```bash
source /home/user/catkin_ws/devel/setup.bash
```
如果路径中包含空格或特殊字符,但未正确使用引号包裹路径,会触发语法错误。正确的写法应为:
```bash
source "/home/user/catkin_ws/devel/setup.bash"
```
此外,如果 `setup.bash` 文件本身未生成(如构建失败),则即使 `.bashrc` 配置无误,也会在每次启动终端时报错。
#### 构建与运行流程
在完成构建并成功生成 `setup.bash` 后,可执行以下步骤启动 ROS 环境:
```bash
roscore
```
在另一个终端中执行已构建的可执行文件:
```bash
rosrun test_pkg for_cpp
```
该流程要求 `test_pkg` 包已正确构建,并且 `CMakeLists.txt` 中已声明 `for_cpp` 为可执行文件 [^1]。
---
阅读全文
相关推荐



















