How to stop mingw and msys from mangling path names given at the command line?

匿名 (未验证) 提交于 2019-12-03 01:55:01

问题:

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?

回答1:

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 as mingw32-make.

Or you could try Cygwin, ideally with a Cygwin build of the toolchain.



回答2:

There is a way to suppress the path translation by setting MSYS_NO_PATHCONV=1 in Windows Git MSys or MSYS2_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_NO_PATHCONV=1 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


回答3:

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.



回答4:

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/".



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!