[英]How to stop gcc from passing -L with standard library paths to the linker
I have a script that needs to prevent gcc from passing -L
with the standard library paths to ld
. 我有一个脚本需要阻止gcc传递
-L
与标准库路径到ld
。 Using -nostdlib
inhibits the -lc -lgcc
etc. but not the -L
. 使用
-nostdlib
抑制-lc -lgcc
等但不抑制-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. 使用
-Wl,-nostdlib
可防止链接器使用自己的标准路径,但不会阻止gcc使用标准路径传递-L
。 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在库路径中没有任何内容调用链接器期望我在命令行上显式写入的目录?
I found a solution but it depends on gcc 4.4 or later for the -wrapper
option (slightly updated version of the script): 我找到了一个解决方案,但它依赖于gcc 4.4或更高版本的
-wrapper
选项(稍微更新了脚本版本):
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
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. 我的这个包装器的版本被调整为重新添加备用
crt1.o
和libc
和libgcc
文件来代替它阻止访问的文件,但是你可以在需要时轻松省略它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.