Permission Denied Errors in Makefile with Go
Despite successfully running "go run ." directly, users encounter permission denied errors when invoking "make run" to execute the same command via a Makefile. This discrepancy can be attributed to a subtlety within GNU make, as revealed by the "make -d" debugging output.
The problem arises when GNU make attempts to locate the go executable. If a directory named "go" exists in a directory specified in the PATH environment variable (preceding the actual directory containing the executable), GNU make will mistakenly target this directory instead of the executable.
For instance, if a directory "/usr/bin/go/" exists and "/usr/bin" is in the PATH, GNU make will encounter a permission denied error when attempting to execute "go run .". To resolve this issue, ensure that your PATH does not contain any directories with "go" subdirectories.
If removing the problematic directories from the PATH is not feasible, you can instruct GNU make to invoke a shell by adding a semicolon ";" to the Makefile target definition. This ensures that the go executable is properly resolved, resolving the permission denied errors.
run: go run . ;
The above is the detailed content of Why Do Makefile Commands Involving \'go run\' Result in Permission Denied Errors?. For more information, please follow other related articles on the PHP Chinese website!