从Makefile设置LD_LIBRARY_PATH [英] set LD_LIBRARY_PATH from Makefile
问题描述
如何从Makefile中设置LD_LIBRARY_PATH env变量?
How do I set the LD_LIBRARY_PATH env variable from a Makefile?
我有一些链接到共享库的源代码,而该共享库又链接到另一个共享库(大于1)。用于构建应用程序的Makefile仅知道第一个共享库。
I have some source code that links to a shared library that in turn links to a different shared library (more than 1). The Makefile for building the application only knows about the first shared library.
如果要构建它,则必须指定:
#export LD_LIBRARY_PATH = / path / to / the / shared / libs
(用于bash)
,并且工作正常。
If I want to build this, I have to specify:
#export LD_LIBRARY_PATH=/path/to/the/shared/libs
(for bash)
and that works fine.
但是,我想从Makefile本身执行此操作。
However, I would like to do this from the Makefile itself.
推荐答案
是的, export是要使用的正确指令。 此处详细记录了该文档。这与make本身用于将变量传播到子make的机制相同。缺点是您不能选择性地将变量传递给某些命令,而不能传递给其他命令。
Yes, "export" is the correct directive to use. It is documented in detail here. This is the same mechanism as make itself uses to propagate variables to sub-makes. The drawback is that you cannot selectively pass down the variable to some commands and not to others.
我可以想到另外两个选项:
There are two other options I can think of:
- 使用
.EXPORT_ALL_VARIABLES
(在某处指定为目标),将所有变量导出到以下环境 -
在命令行上指定:
- Using
.EXPORT_ALL_VARIABLES
(specify as a target somewhere), causes all variables to be exported to the environment of sub-commands. Specify on the command line:
foo:
EXPORTEDVAR=somevalue gcc $< -o $@
这篇关于从Makefile设置LD_LIBRARY_PATH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!