为了账号安全,请及时绑定邮箱和手机立即绑定

从 Makefile 运行时权限被拒绝

从 Makefile 运行时权限被拒绝

Go
海绵宝宝撒 2023-02-21 16:11:13
我遇到了一些奇怪的权限被拒绝错误,我不知道可能来自哪里。$ go run .Hello from go$ make rungo run .make: go: Permission deniedmake: *** [Makefile:2: run] Error 127$ make run2echo "Make says hello" ; go run .Make says helloHello from go$ cat Makefile run:    go run .run2:    echo "Make says hello" ; go run .$ cat main.go package mainimport "fmt"func main() {    fmt.Println("Hello from go")}我的终端是在 Ubuntu 22.04 上运行的 bash。run我的目标和直接运行 go 会导致权限被拒绝错误有什么区别?run和run2允许它在其中一个工作而不在另一个工作之间有什么区别?编辑:使用-d/运行 make--trace$ make -d run<...snip...> No need to remake target 'Makefile'.Updating goal targets....Considering target file 'run'. File 'run' does not exist. Finished prerequisites of target file 'run'.Must remake target 'run'.go run .make: go: Permission deniedmake: *** [Makefile:2: run] Error 127$ make --trace runMakefile:2: target 'run' does not existgo run .make: go: Permission deniedmake: *** [Makefile:2: run] Error 127$ make --trace run2Makefile:5: target 'run2' does not existecho "Make says hello"; go run .Make says helloHello from go
查看完整描述

2 回答

?
牛魔王的故事

TA贡献1830条经验 获得超3个赞

这是由于 GNU make 中的错误(实际上是 gnulib 中的错误)。这意味着您在您的某个目录中有一个名为 的目录(在包含可执行文件的实际目录之前)。goPATHgo

因此,如果您有一个目录 /usr/bin/go/.并且在/usr/bin您的 上PATH,您将看到此问题。

您应该检查PATH并确保删除包含此类子目录的所有目录。如果你不能从你的目录中删除那个目录PATH(需要包含你的子目录的目录是不寻常的,PATH但我想这是可能的)并且你不能将目录重命名go为其他东西,你必须确保 GNU make 调用 shell , 通过添加特殊字符。就;足够了:

run:     
    go run . ;


查看完整回答
反对 回复 2023-02-21
?
芜湖不芜

TA贡献1796条经验 获得超7个赞

您遇到的问题可能是由于您的 shell 和Makefile. 例如,如果你有一个 shell 别名,go这个Makefile别名对Makefile. 很难猜测差异可能在哪里。


您可能想尝试通过在您的以下内容中尝试调试问题Makefile:


echo $(PATH)

command -v go

并在您的 shell 中运行相同的命令并比较结果。


请注意,默认的 shellMakefile是/bin/sh而你可能有bashor zsh。


这里有一些方便的默认值来配置你的Makefile构建:


LANG=en_US.UTF-8

SHELL=/bin/bash

.SHELLFLAGS=--norc --noprofile -e -u -o pipefail -c


查看完整回答
反对 回复 2023-02-21
  • 2 回答
  • 0 关注
  • 310 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信