Makefile make install not executing multiple line commands
make
is almost certainly executing both lines of commands. However, the line export LD_LIBRARY_PATH=$<
(or whatever make
expands it) gets executed by a shell that's a child process of the make
process. When you type echo $LD_LIBRARY_PATH
, you get whatever the environment variable LD_LIBRARY_PATH had in it. Your shell didn't execute the "export", a sub-process of make
executed it. You'll have to do the export in your .bashrc
or .zshrc
or whatever file, or type it in manually.
Related videos on Youtube
tonga
Updated on September 18, 2022Comments
-
tonga almost 2 years
I have a Makefile that contains an
install
section to allow me tomake install
after building the source code. Theinstall
section contains two lines of shell commands:install: /usr/local/lib cp $(LIB_OBJ) $< export LD_LIBRARY_PATH=$<
So the first line copies the libxxx.so to
/usr/local/lib
and the second line sets the environmental variableLD_LIBRARY_PATH
to/usr/local/lib
so that final executable can find the libxxx.so file.But when I run
make install
from the command line and then type:echo $LD_LIBRARY_PATH
It shows empty content rather than
/usr/local/lib
as intended. So why is the second line of command in the Makefile not executed? -
tonga over 9 yearsThanks. So there is no way to put
export LD_LIBRARY_PATH=
in Makefile so that when user typemake install
, all libraries built will be in the path? If I export it in.bashrc
, it will be permanently set. So I don't want to do that. If I need to manually export it, thenmake install
is not automatic. -
Admin over 9 yearsThere might be some weird trick. After all you can re-TTY a process with "reptyr" (github.com/nelhage/reptyr). There's probably some
gdb
stunt you could do to change LD_LIBRARY_PATH, but I don't think you should do those stunts on a regular basis. -
tonga over 9 yearsI put the export command before install but it didn't work. I even put the two commands in one line but not working either.
-
tonga over 9 yearsSo what is the rationale that the multiline command is executed by a sub-process of make, instead of by the make process itself? Is this designed intentionally in make utility?
-
eyoung100 over 9 yearsAre you "piping"
LIB_OBJ
intoLD_LIBRARY_PATH
? I've never seen$<
as in your OP. -
tonga over 9 yearsNo,
$<
is just an automatic variable used by Makefile to denote the first argument in the rule, which is /usr/local/lib. -
Admin over 9 yearsI don't think the distinction is multiline vs single line, I think it's if the command(s) contain a shell metacharacter (>, &, ;, etc) then
make
shells out rather than just forking and execing. The rationale here is probably, "it's really hard to parse shell command lines correctly, let's just hand all the hard work off to the shell."