You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS Code SSH模式下Makefile Tools执行shell命令失败求助

VS Code SSH构建Makefile时find命令路径错误的解决方法

问题描述

Win11通过SSH连接Ubuntu服务器,使用VS Code开发C项目,项目采用Makefile管理,其中通过shell的find命令收集C文件:

SRCDIR := components/my_sources
SRCS := $(shell find $(SRCDIR) -name '*.c')

在VS Code终端执行make可成功完成构建,但使用VS Code内置构建功能时失败,报错:

find: ‘components/my_sources’: No such file or directory

经排查,终端直接执行find命令能正常获取文件列表,尝试改用全路径作为find命令输入仍无效。

解决方案

  • 配置tasks.json指定工作目录
    VS Code的构建任务默认工作目录可能不是项目根目录,需在.vscode/tasks.json中明确设置cwd为项目根路径:

    {
      "version": "2.0.0",
      "tasks": [
        {
          "label": "build",
          "type": "shell",
          "command": "make",
          "args": [],
          "options": {
            "cwd": "${workspaceFolder}"
          },
          "group": {
            "kind": "build",
            "isDefault": true
          },
          "problemMatcher": ["$gcc"]
        }
      ]
    }
    
  • 确认远程会话的工作目录
    检查VS Code远程SSH连接时打开的是否为项目根文件夹,若打开的是子文件夹,${workspaceFolder}会指向该子目录,导致路径错误。需重新打开项目根目录。

  • Makefile中使用绝对路径(可选)
    在Makefile中基于$(CURDIR)定义绝对路径,确保find命令的起始路径始终准确:

    SRCDIR := $(CURDIR)/components/my_sources
    SRCS := $(shell find $(SRCDIR) -name '*.c')
    

内容的提问来源于stack exchange,提问作者LYB

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 17:02:17