0

I'm currently trying to run my makefile which is as follows:

run program:
        export CUDA_VISIBLE_DEVICES=1
        python ~/program/main.py --setup2

I receive a Permission denied error when I try to run the export shell command. I'm assuming the reason is because I'm currently using a lab's server to run this program, and usually only a designated few are granted permission for many of the server's functionalities.

However, whenever I run this command "manually" (i.e. typing out both lines of the makefile myself in the terminal), it runs fine.

I've also taken a look at How to use shell commands in Makefile and shell script run when I am root but I get a permission denied when it is invoked from a Makefile (still as root) and tried to change the line export CUDA_VISIBLE_DEVICES=1 to "$(export CUDA_VISIBLE_DEVICES=1)" and "$(shell export CUDA_VISIBLE_DEVICES=1)" but I get the same permission error.

Is there a way that I can go around this issue, or will I have to talk to the server manager? Thanks.

Sean
  • 2,890
  • 8
  • 36
  • 78
  • 1
    Make's `export` directive and the the shell `export` command are not the same thing. But the main problem here is the permission error. I am surprised that that error even exists, and I don't know enough system administration to understand why it's happening. I suggest you try `echo $SHELL; whoami` in the command line, and `echo $$SHELL; whoami` in the makefile rule, to rule some things out. Also, which version of Make are you using? (You can check with `make -v`.) – Beta Nov 15 '19 at 00:53
  • My make version is `4.1` and when I ran the file as you suggested I get the output `/bin/bash \ user`. The output is the same as when I run the `echo` command in the terminal. – Sean Nov 15 '19 at 00:59
  • Use 'make -d run' to get debugging information. Also, can you share command line, and full log file ? – dash-o Nov 15 '19 at 06:02
  • I think you're making an invalid assumption about where the error is happening: `export` isn't a command, and won't cause a `permission denied` error. Can you provide a complete example that produces the error, along with the _exact output_, with the error, you see from that example? – Guildencrantz Nov 15 '19 at 21:51

1 Answers1

0

There might be some confusion between make export, and the shell export.

Outside a rule, the 'export' is directive, manipulating the make environment - usually in the context communicating between sub-makes.

When you put it into a rule (after ), it will get executed by the it's own sub-shell, which will be a no-op (the python command on the next line does not share env with the export on the first line). Consider changing rule to:

run program:
<TAB>    CUDA_VISIBLE_DEVICES=1 python ~/program/main.py --setup2

Out of curiosity, why are there two targets (run, program) used here ?

dash-o
  • 13,723
  • 1
  • 10
  • 37