如何从标准库路径传递-L到连接器停止GCC [英] How to stop gcc from passing -L with standard library paths to the linker

查看:136
本文介绍了如何从标准库路径传递-L到连接器停止GCC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本,需要prevent GCC从通过 -L 与标准库路径 LD 。使用 -nostdlib 抑制 -lc -lgcc 等,而不是 -L 。使用轮候册,-nostdlib $ P $使用自己的标准路径pvents连接器,但不从通过 -L 与标准路径。有没有什么办法,以确保海合会调用没事库路径链接想到我在命令行上明确写的目录?

I have a script that needs to prevent gcc from passing -L with the standard library paths to ld. Using -nostdlib inhibits the -lc -lgcc etc. but not the -L. Using -Wl,-nostdlib prevents the linker from using its own standard path, but doesn't stop gcc from passing -L with the standard paths. Is there any way to ensure that gcc calls the linker with nothing in the library path expect the directories I explicitly write on the command line?

推荐答案

我发现了一个解决方案,但是它依赖于GCC 4.4或更高版本的 -wrapper 选项(略有更新脚本的版本):

I found a solution but it depends on gcc 4.4 or later for the -wrapper option (slightly updated version of the script):

inc=/path/to/alt/incl
lib=/path/to/alt/libs
crt=/path/to/alt/crt1.o
gcc -wrapper sh,-c,'
x= ; z= ; s= ; for i ; do
[ "$z" ] || set -- ; z=1
case "$i" in
-shared) s=1 ; set -- "$@" "$i" ;;
-Lxxxxxx) x=1 ;;
-xxxxxx) x= ; [ "$s" ] || set -- "$@" '"'$crt'"' ;;
*) [ "$x" ] || set -- "$@" "$i" ;;
esac
done
exec "$0" "$@"
' -nostdinc -nostdlib -isystem "$inc" -Wl,-xxxxxx "$@" -L"$lib" -Lxxxxxx -Wl,-nostdlib -lc -lgcc

我该包装的版本被调整到重新添加备用 crt1.o 的libc libgcc中到位了prevents访问的人的文件,但如果需要,你可以很容易忽略它们。

My version of this wrapper is tuned to re-add alternate crt1.o and libc and libgcc files in place of the ones it prevents access to, but you could just as easily omit them if needed.

这篇关于如何从标准库路径传递-L到连接器停止GCC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆