bash 如何添加 include 和 lib 路径来配置/制作循环?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7561509/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add include and lib paths to configure/make cycle?
提问by Lacrymology
I need a place to install libraries in a linux box I have no su access to. I'm using ~/local[/bin,/lib,/include], but I don't know how can I tell ./configure to look for libraries there (particularly, I'm trying to compile emacs, which needs libgif, which doesn't come in my distro).
我需要一个地方在我没有 su 访问权限的 linux 盒子中安装库。我正在使用 ~/local[/bin,/lib,/include],但我不知道如何告诉 ./configure 在那里查找库(特别是,我正在尝试编译需要 libgif 的 emacs ,这在我的发行版中没有)。
I tried adding
我尝试添加
export PATH=$PATH:~/local/bin
export LD_LIBRARY_PATH=~/local/lib
export C_INCLUDE_PATH=~/local/include
export CPLUS_INCLUDE_PATH=~/local/include
to .bashrc but it doesn't seem to work.
到 .bashrc 但它似乎不起作用。
回答by William Pursell
You want a config.site file. Try:
你想要一个 config.site 文件。尝试:
$ mkdir -p ~/local/share $ cat << EOF > ~/local/share/config.site CPPFLAGS=-I$HOME/local/include LDFLAGS=-L$HOME/local/lib ... EOF
Whenever you invoke an autoconf generated configure script with --prefix=$HOME/local, the config.site will be read and all the assignments will be made for you. CPPFLAGS and LDFLAGS should be all you need, but you can make any other desired assignments as well (hence the ... in the sample above). Note that -I flags belong in CPPFLAGS and not in CFLAGS, as -I is intended for the pre-processor and not the compiler.
每当您使用 --prefix=$HOME/local 调用 autoconf 生成的配置脚本时,将读取 config.site 并为您进行所有分配。CPPFLAGS 和 LDFLAGS 应该是您所需要的,但您也可以进行任何其他所需的分配(因此是上面示例中的 ...)。请注意,-I 标志属于 CPPFLAGS 而不是 CFLAGS,因为 -I 用于预处理器而不是编译器。
回答by long404
Set LDFLAGS and CFLAGS when you run make:
运行 make 时设置 LDFLAGS 和 CFLAGS:
$ LDFLAGS="-L/home/me/local/lib" CFLAGS="-I/home/me/local/include" make
If you don't want to do that a gazillion times, export these in your .bashrc (or your shell equivalent). Also set LD_LIBRARY_PATH to include /home/me/local/lib:
如果您不想这样做无数次,请将它们导出到您的 .bashrc(或您的 shell 等效文件)中。还要设置 LD_LIBRARY_PATH 以包含 /home/me/local/lib:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/me/local/lib
回答by Samuel
This took a while to get right. I had this issue when cross-compiling in Ubuntu for an ARM target. I solved it with:
这需要一段时间才能正确。我在 Ubuntu 中为 ARM 目标交叉编译时遇到了这个问题。我用以下方法解决了它:
PATH=$PATH:/ccpath/bin CC=ccname-gcc AR=ccname-ar LD=ccname-ld CPPFLAGS="-nostdinc -I/ccrootfs/usr/include ..." LDFLAGS=-L/ccrootfs/usr/lib ./autogen.sh --build=`config.guess` --host=armv5tejl-unknown-linux-gnueabihf
Notice CFLAGS is not used with autogen.sh/configure, using it gave me the error: "configure: error: C compiler cannot create executables". In the build environment I was using an autogen.sh script was provided, if you don't have an autogen.sh script substitute ./autogen.sh with ./configure in the command above. I ran config.guess on the target system to get the --host parameter.
注意 CFLAGS 不与 autogen.sh/configure 一起使用,使用它会给我错误:“配置:错误:C 编译器无法创建可执行文件”。在我使用的构建环境中,提供了 autogen.sh 脚本,如果您没有 autogen.sh 脚本,则在上面的命令中将 ./autogen.sh 替换为 ./configure。我在目标系统上运行 config.guess 以获取 --host 参数。
After successfully running autogen.sh/configure, compile with:
成功运行 autogen.sh/configure 后,编译:
PATH=$PATH:/ccpath/bin CC=ccname-gcc AR=ccname-ar LD=ccname-ld CPPFLAGS="-nostdinc -I/ccrootfs/usr/include ..." LDFLAGS=-L/ccrootfs/usr/lib CFLAGS="-march=... -mcpu=... etc." make
The CFLAGS I chose to use were: "-march=armv5te -fno-tree-vectorize -mthumb-interwork -mcpu=arm926ej-s". It will take a while to get all of the include directories set up correctly: you might want some includes pointing to your cross-compiler and some pointing to your root file system includes, and there will likely be some conflicts.
我选择使用的 CFLAGS 是:“-march=armv5te -fno-tree-vectorize -mthumb-interwork -mcpu=arm926ej-s”。正确设置所有包含目录需要一些时间:您可能希望一些包含指向您的交叉编译器,一些包含指向您的根文件系统包含,并且可能会有一些冲突。
I'm sure this is not the perfect answer. And I am still seeing some include directories pointing to / and not /ccrootfs in the Makefiles. Would love to know how to correct this. Hope this helps someone.
我敢肯定这不是完美的答案。我仍然看到一些包含目录指向 / 而不是 /ccrootfs 在 Makefile 中。很想知道如何纠正这个问题。希望这可以帮助某人。