gmake 覆盖编译器目录
有没有办法指定 gmake 备用编译器目录。即:我安装了多个编译器并尝试在编译时使用备用 gcc。
就像我指定它使用新指定的 gcc 一样。
gmake CC=/opt/crosstool/gcc-3.2.2-glibc-2.2.5/i686-unknown-linux-gnu/i686-unknown-linux-gnu/bin/gcc
CXX=/opt/crosstool/gcc-3.2.2-glibc-2.2.5/i686-unknown-linux-gnu/i686-unknown-linux-gnu/bin/g++
LD=/opt/crosstool/gcc-3.2.2-glibc-2.2.5/i686-unknown-linux-gnu/i686-unknown-linux-gnu/bin/gcc
AR=/opt/crosstool/gcc-3.2.2-glibc-2.2.5/i686-unknown-linux-gnu/i686-unknown-linux-gnu/bin/ar
我试图避免的是为所有工具指定绝对路径。我正在尝试类似的事情
gmake COMPILER_DIR=/opt/crosstool/gcc-3.2.2-glibc-2.2.5/i686-unknown-linux-gnu/i686-unknown-linux-gnu/
也可能适合作为交叉编译器问题。
Is there any way to specify gmake an alternate compiler directory. ie: i have multiple compilers installed and trying to use alternate gcc while compilation.
like if i specify it uses the new specified gcc.
gmake CC=/opt/crosstool/gcc-3.2.2-glibc-2.2.5/i686-unknown-linux-gnu/i686-unknown-linux-gnu/bin/gcc
CXX=/opt/crosstool/gcc-3.2.2-glibc-2.2.5/i686-unknown-linux-gnu/i686-unknown-linux-gnu/bin/g++
LD=/opt/crosstool/gcc-3.2.2-glibc-2.2.5/i686-unknown-linux-gnu/i686-unknown-linux-gnu/bin/gcc
AR=/opt/crosstool/gcc-3.2.2-glibc-2.2.5/i686-unknown-linux-gnu/i686-unknown-linux-gnu/bin/ar
what i am trying to avoid is specify absolute path for all tools. i am trying something like
gmake COMPILER_DIR=/opt/crosstool/gcc-3.2.2-glibc-2.2.5/i686-unknown-linux-gnu/i686-unknown-linux-gnu/
this might fit as a cross-compiler question also.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 makefile 中,您可以使用如下内容:
如果您未定义
COMPILER_DIR
,则将使用普通系统gcc
,否则从您的目录中使用。In the makefile you can use something like this:
If you do not define
COMPILER_DIR
then the normal systemgcc
will be used, otherwise from your directory.以下是 crosstool tool chainkit 的建议,仅供将来参考。
方法一
不要使用完整的
/opt/crosstool/gcc-3.2.2-glibc-2.2.5/i686-unknown-linux-gnu/i686-unknown-linux-gnu/bin/
使用PATH=/opt/crosstool/gcc-3.2.2-glibc-2.2.5/i686-unknown-linux-gnu/bin
并在 make 文件中保留CC=$(CROSSCOMPILERVERSION)gcc
其中CROSSCOMPILERVERSION=i686-unknown-linux-gnu
不知怎的,这个设置效果最好,但仍然不确定如何。方法2
使用方法 1 中建议的路径,但另外在 crosstool bin 目录中创建软链接。就像在
/opt/crosstool/gcc-3.2.2-glibc-2.2.5/i686-unknown-linux-gnu/bin
中添加i686-unknown-linux-gnu-gcc的软链接作为gcc。这比更改 makefile 更容易(或者在您没有更改 makefile 的权限的情况下)Just for future reference here's how crosstool tool chainkit suggest.
Method 1
Instead of using complete
/opt/crosstool/gcc-3.2.2-glibc-2.2.5/i686-unknown-linux-gnu/i686-unknown-linux-gnu/bin/
usePATH=/opt/crosstool/gcc-3.2.2-glibc-2.2.5/i686-unknown-linux-gnu/bin
and in make files keepCC=$(CROSSCOMPILERVERSION)gcc
whereCROSSCOMPILERVERSION=i686-unknown-linux-gnu
somehow this setup works best, still not sure how.Method 2
Use the path as suggested in method.1 but additionally create softlink in crosstool bin dir. like in
/opt/crosstool/gcc-3.2.2-glibc-2.2.5/i686-unknown-linux-gnu/bin
add softlink of i686-unknown-linux-gnu-gcc as gcc. This is easier than changing makefile (or in cas you dont have permission to change makefiles)当您构建
binutils
和gcc
时,它们会安装在两个不同的路径中:bin/PREFIX-gcc
PREFIX/bin/gcc
>这允许您在路径中拥有多个交叉编译器,每个交叉编译器具有不同的可执行文件名称,但您也可以简单地将第二个变体放入路径中,这样
gcc
现在就是选择的交叉版本。这对于 Makefile 很有用。您的示例已使用第二种形式:
/opt/crosstool/gcc-3.2.2-glibc-2.2.5/i686-unknown-linux-gnu/i686-unknown-linux-gnu/bin/ar
与/opt/crosstool/gcc-3.2.2-glibc-2.2.5/i686-unknown-linux-gnu/bin/i686-unknown-linux-gnu-ar
(它可能也存在于您的系统)。因此,您可以使用 PATH=/opt/crosstool/gcc-3.2.2-glibc-2.2.5/i686-unknown-linux-gnu/i686-unknown-linux-gnu/bin/:$PATH make 进行构建。 .. 现在默认的
gcc
将是交叉版本。When you build
binutils
andgcc
they install in two different paths:bin/PREFIX-gcc
PREFIX/bin/gcc
This allows you to have several cross compilers in your path each with different executables names, but you can also simply put the second variant in your path such that
gcc
is now the cross version of choice. This is useful for Makefiles.Your example already uses the second form:
/opt/crosstool/gcc-3.2.2-glibc-2.2.5/i686-unknown-linux-gnu/i686-unknown-linux-gnu/bin/ar
as opposed to/opt/crosstool/gcc-3.2.2-glibc-2.2.5/i686-unknown-linux-gnu/bin/i686-unknown-linux-gnu-ar
(which probably also exists on your system).So you can build with
PATH=/opt/crosstool/gcc-3.2.2-glibc-2.2.5/i686-unknown-linux-gnu/i686-unknown-linux-gnu/bin/:$PATH make ...
and now the defaultgcc
will be the cross version.