如何阻止 MinGW 和 MSYS 修改命令行中给出的路径名 [英] How to stop MinGW and MSYS from mangling path names given at the command line

查看:28
本文介绍了如何阻止 MinGW 和 MSYS 修改命令行中给出的路径名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Windows 上,我正在使用 CodeSourcery 的交叉编译器套件为 ARM/Linux 交叉编译一个程序.我使用 MinGW MSYS 作为我的命令解释器,它经常会破坏我的路径和路径名.例如,为了构建我的程序,我调用

On Windows, I'm cross-compiling a program for ARM/Linux using CodeSourcery's cross-compiler suite. I use MinGW MSYS as my command interpreter, and very often it will mangle my paths and pathnames. For example, to build my program, I invoke

arm-none-linux-gnueabi-gcc.exe -Wall -g 
    -Wl,--dynamic-linker=/usr/lib/myrpath/ld-linux.so.3 
    -Wl,-rpath=/usr/lib/myrpath 
    -I../targetsysroot/usr/include 
    myprogram.c -o myprogram

当然,我希望 /usr/lib/myrpath 逐字插入 myprogram 可执行文件 - 我正在编译的 ARM Linux 目标不使用 MinGW 或MSYS.但这是最终的结果:

Of course, I want /usr/lib/myrpath inserted verbatim into the myprogram executable - the ARM Linux target I'm compiling for doesn't use MinGW or MSYS. But here's what ends up going into it:

...
0x0000000f (RPATH)            Library rpath: [C:/MinGW/msys/1.0/lib/myrpath]
...

不完全是我想要的.如果我直接在 cmd.exe 命令行上调用 GCC,我会在可执行文件中获得正确的 rpath.如果我在 MSYS 命令行上调用 GCC,我会得到损坏的 rpath.如果我使用从 cmd.exe 命令行使用 make 运行的 Makefile 调用 GCC,我仍然会得到一个损坏的 rpath (!)

Not exactly what I wanted. If I invoke GCC on the cmd.exe command line directly, I get the right rpath in the executable. If I invoke GCC on the MSYS command line, I get the mangled rpath. If I invoke GCC with a Makefile that is run with make from the cmd.exe command line, I still get a mangled rpath (!)

有什么想法可以关闭这种烦人的行为吗?

Any ideas how I might turn off this annoying behavior?

推荐答案

我刚刚发现了一个巧妙的技巧,可以避免 MSYS/MinGW 为您转换路径.

I just discovered a neat trick to avoid MSYS/MinGW translating the paths for you.

如果您使用双斜线开始路径,那么 MSYS 不会将路径转换为 ​​DOS 格式.所以在 OP 的例子中,-rpath 开关应该像这样指定:

If you use double-slash to start the path, then MSYS won't translate the path to DOS format. So in OP's example, the -rpath switch should be specified like this:

-Wl,-rpath=//usr/lib/myrpath

所有 Unix/Linux 工具似乎都可以毫无问题地处理这种虚假斜杠,因此即使您的二进制文件的 rpath 以//usr/开头...我认为加载程序会做正确的事情.

All Unix/Linux tools seem to handle such spurious slashes without any problem, so even though your binary's rpath will start with //usr/... I think the loader will do the right thing.

这篇关于如何阻止 MinGW 和 MSYS 修改命令行中给出的路径名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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