开发者

How to stop MinGW and MSYS from mangling path names given at the command line

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开发者_如何学JAVA 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?


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


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.


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.


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 use MSYS_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:

  • For MSYS2 (built-in): MSYS2_ARG_CONV_EXCL="*"
  • For Git for Windows (built-in): MSYS_NO_PATHCONV=1
  • For MinGW.org (with msys-core-extended): MSYS_NO_PATHCONV=1.


export MSYS_NO_PATHCONV=1 was necessary in my case on git-bash on windows (as noted by dx_over_dt above. )


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜