在 Windows 上,我使用 CodeSourcery 的交叉编译器套件交叉编译 ARM/Linux 程序。我使用 MinGW MSYS 作为命令解释器,它经常会破坏我的路径和路径名。例如,要构建我的程序,我调用
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 目标for 不使用 MinGW 或 MSYS。但最终的结果是这样的:
...
0x0000000f (RPATH) Library rpath: [C:/MinGW/msys/1.0/lib/myrpath]
...
不完全是我想要的。如果我直接在 cmd.exe 命令行上调用 GCC,我会在可执行文件中获得正确的 rpath。如果我在 MSYS 命令行上调用 GCC,我会得到损坏的 rpath。如果我使用从 cmd.exe 命令行使用 make 运行的 Makefile 调用 GCC,我仍然会得到一个损坏的 rpath (!)
有什么想法可以关闭这种烦人的行为吗?
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
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]
...
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?
发布评论
评论(6)
有一种方法可以通过设置来抑制路径转换Windows Git MSys 中的
MSYS_NO_PATHCONV=1
或 MSYS2_ARG_CONV_EXCL="*" href="https://github.com/msys2/msys2/wiki/Porting#filesystem-namespaces" rel="noreferrer">MSYS2。或者,您可以通过将赋值放在命令本身之前,仅临时为该命令设置变量:
There is a way to suppress the path translation by setting
MSYS_NO_PATHCONV=1
in Windows Git MSys orMSYS2_ARG_CONV_EXCL="*"
in MSYS2.Alternatively, you can set the variable only temporarily just for that command by putting the assignment just before the command itself:
我刚刚发现了一个巧妙的技巧来避免 MSYS/MinGW 为您转换路径。
如果您使用双斜杠来启动路径,则 MSYS 不会将路径转换为 DOS 格式。因此,在OP的示例中,-rpath开关应该这样指定:
-Wl,-rpath=//usr/lib/myrpath
所有 Unix/Linux 工具似乎都可以毫无问题地处理此类虚假斜杠,所以即使你的二进制文件的 rpath 将以 //usr/... 开头,我认为加载程序会做正确的事情。
I just discovered a neat trick to avoid MSYS/MinGW translating the paths for you.
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
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.
我不认为有办法关闭它。 MSYS 是旧 Cygwin 版本的一个分支,进行了许多旨在改进 Windows 集成的调整,其中调用本机 Windows 程序时的自动 POSIX 路径转换可以说是最重要的。这样做的问题在于,并不总是能够判断一个参数是一条路径还是其他东西,或者像在本例中一样,它实际上是否是一条不应该被翻译的路径。翻译由一组启发式指导。
您可以尝试使用 MinGW make 而不是 MSYS make(是的,它们是不同的东西),这是一个原生 Windows 构建的 make,没有 POSIX 路径支持和转换。使用
mingw-get install mingw32-make
安装并作为mingw32-make
调用。或者您可以尝试 Cygwin,最好使用 Cygwin 构建的工具链。
I don't think there's a way to switch this off. MSYS is a fork of an old Cygwin version with a number of tweaks aimed at improved Windows integration, whereby the automatic POSIX path translation when invoking native Windows programs is arguably the most significant. The trouble with that is that it isn't always possible to tell whether an argument is a path or something else, or whether, as in this case, it is in fact a path that nevertheless shouldn't be translated. The translation is guided by a set of heuristics.
You could try using MinGW make instead of MSYS make (yes, they're different things), which is a native Windows build of make without POSIX path support and conversion. Install with
mingw-get install mingw32-make
and invoke asmingw32-make
.Or you could try Cygwin, ideally with a Cygwin build of the toolchain.
事实上,在 MinGW.org 提供的原始 MSYS 项目中,没有办法 禁用 Posix 路径转换。
这就是为什么我对 msys-core 运行时进行了一个小分支,它支持
MSYS_NO_PATHCONV
标志随 Git for Windows 分叉引入。这样,您就可以像在 Git for Windows 中一样使用MSYS_NO_PATHCONV
环境变量,但在原始的 MinGW/MSYS 中。总之,要禁用此 Posix 路径转换:
MSYS2_ARG_CONV_EXCL="*"
MSYS_NO_PATHCONV=1
MSYS_NO_PATHCONV=1
。Indeed, in the original MSYS project provided by MinGW.org, there is no way to disable the Posix path conversion.
That's why I made a little fork of the msys-core runtime which supports the
MSYS_NO_PATHCONV
flag introduced with the Git for Windows fork. In that way, you may useMSYS_NO_PATHCONV
environment variable as in the Git for Windows but in the original MinGW/MSYS.So in summary, to disable this Posix path convesion:
MSYS2_ARG_CONV_EXCL="*"
MSYS_NO_PATHCONV=1
MSYS_NO_PATHCONV=1
.在我的情况下,在 Windows 上的 git-bash 上,导出 MSYS_NO_PATHCONV=1 是必要的(如上面 dx_over_dt 所指出的。)
export MSYS_NO_PATHCONV=1 was necessary in my case on git-bash on windows (as noted by dx_over_dt above. )
不幸的是,为此示例添加两个正斜杠并不能按预期工作。
rsync -rvztn --delete --exclude="/application/logs/" ...
我希望“rsync”仅排除位于顶层的 /application/logs 中的文件,因此前面有正斜杠。添加两个正斜杠不会导致它排除该目录。我不得不求助于不太准确的
--exclude="application/logs/"
。Unfortunately putting two forward slashes for this example doesn't work as expected.
rsync -rvztn --delete --exclude="/application/logs/" ...
I want 'rsync' to exclude files only at /application/logs which is at the top level, hence the leading forward slash. Adding two forward slashes will not cause it to exclude this directory. I have to resort to the less accurate
--exclude="application/logs/"
.