[UPDATE: This is not really wrong, but not really right either. See below.]
I was a bit surprised at this problem, but I suppose most people use standard
gcc to build… I want to build my project with a version of OMake that I have compiled and installed in my home directory. I have
~/tools/bin in my
PATH, but for some reason
M-x compile still gives me
/bin/bash: omake: command not found
The trick is that Emacs invokes the compile command in a non-interactive, non-login shell, which means that neither your
.bash_profile nor your
.bashrc (or any variations thereof) are going to get read.* The workaround is to set
BASH_ENV to point to a script file that sets your
bash reads the file pointed-to by
BASH_ENV in non-interactive mode. Here’s my solution:
# In ~/.bash_profile: . ~/.bashrc # In ~/.bashrc: export BASH_ENV=~/.bash_env . "$BASH_ENV" # In ~/.bash_env: export PATH=/home/chris/tools/bin:$PATH
There’s probably a good reason why this is a bad idea, but it works.
* A quick refresher course:
.bash_profile is for login shells;
.bashrc is for interactive, non-login shells;
BASH_ENV is for non-interactive, non-login shells (which, confusingly, will probably be a sub-process of an interactive and/or login shell, which is why the above example works).
[UPDATE] The compilation shell being non-interactive and non-login is a red herring. While this is certainly the case, a non-interactive, non-login shell will inherit the environment of it’s parent process. So, for instance, if your
PATH is properly set in your shell and you invoke Emacs from the command line, things should be fine.
What was really causing my problem is that I was invoking Emacs from the Gnome Panel. The environment that Emacs inherits in this case is Gnome’s, not Bash’s. How do you change the
PATH in the Gnome environment? Um… Eh…
The solution I’ve settled on is to create a
~/.xsession file as follows,
#! /usr/bin/bash if [ -f ~/.bash_env ]; then . ~/.bash_env fi exec gnome-session
.bash_env is as above.
NOTE: If you leave off the last line, your X session will end before it begins. The
.xsession script is the X process: when it ends, the X process ends. Execing
gnome-session replaces the script process with the Gnome session process.
[UPDATE 2] Of course, another option is to just use
setenv in your
.emacs file. TMTOWTDI, in Emacs and Perl alike.