【记录】Cygwin下把Windows的路径转换为Linux路径

【背景】

折腾:

【未解决】再次研究:Cygwin下编译Buildroot时在编译libtool-2.2.10时出错:configure: error: C compiler cannot create executables

期间,需要把一些cygcheck出来的:

CLi@PC-CLI-1 ~/develop/buildroot/buildroot-2013.05
$ cygcheck /usr/lib/gcc/i686-pc-cygwin/4.5.3/cc1.exe
D:\tmp\tmp_dev_root\cgwin\lib\gcc\i686-pc-cygwin\4.5.3\cc1.exe
  D:\tmp\tmp_dev_root\cgwin\bin\cygcloog-0.dll
    D:\tmp\tmp_dev_root\cgwin\bin\cygwin1.dll
      C:\Windows\system32\KERNEL32.dll
        C:\Windows\system32\API-MS-Win-Core-RtlSupport-L1-1-0.dll
        C:\Windows\system32\ntdll.dll
        C:\Windows\system32\KERNELBASE.dll
        C:\Windows\system32\API-MS-Win-Core-ProcessThreads-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-Heap-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-Memory-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-Handle-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-Synch-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-File-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-IO-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-ThreadPool-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-LibraryLoader-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-NamedPipe-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-Misc-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-SysInfo-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-Localization-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-ProcessEnvironment-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-String-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-Debug-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-ErrorHandling-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-Fibers-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-Util-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Core-Profile-L1-1-0.dll
        C:\Windows\system32\API-MS-Win-Security-Base-L1-1-0.dll
    D:\tmp\tmp_dev_root\cgwin\bin\cyggmp-10.dll
    D:\tmp\tmp_dev_root\cgwin\bin\cygppl_c-4.dll
      D:\tmp\tmp_dev_root\cgwin\bin\cygppl-9.dll
        D:\tmp\tmp_dev_root\cgwin\bin\cyggcc_s-1.dll
        D:\tmp\tmp_dev_root\cgwin\bin\cygstdc++-6.dll
        D:\tmp\tmp_dev_root\cgwin\bin\cyggmpxx-4.dll
      D:\tmp\tmp_dev_root\cgwin\bin\cygpwl-5.dll
  D:\tmp\tmp_dev_root\cgwin\bin\cyggmp-3.dll
  D:\tmp\tmp_dev_root\cgwin\bin\cygiconv-2.dll
  D:\tmp\tmp_dev_root\cgwin\bin\cygintl-8.dll
  D:\tmp\tmp_dev_root\cgwin\bin\cygmpc-1.dll
    D:\tmp\tmp_dev_root\cgwin\bin\cygmpfr-1.dll
  D:\tmp\tmp_dev_root\cgwin\bin\cygmpfr-4.dll
  D:\tmp\tmp_dev_root\cgwin\bin\cygppl_c-2.dll
    D:\tmp\tmp_dev_root\cgwin\bin\cygppl-7.dll
  D:\tmp\tmp_dev_root\cgwin\bin\cygz.dll

中的windows路径:

D:\tmp\tmp_dev_root\cgwin\bin

C:\Windows\system32

转换为Cygwin的路径。

注:其实这些路径相对不复杂,自己都可以手动写出来了。

但是还是要尽量去使用cygwin中的工具,搞懂如何使用,如何转换路径。

【折腾过程】

1.自己试了试,结果没搞懂:

CLi@PC-CLI-1 ~/develop/buildroot/buildroot-2013.05/output/build/host-libtool-2.2.10
$ cygpath --help
Usage: cygpath (-d|-m|-u|-w|-t TYPE) [-f FILE] [OPTION]... NAME...
       cygpath [-c HANDLE]
       cygpath [-ADHOPSW]
       cygpath [-F ID]

Convert Unix and Windows format paths, or output system path information

Output type options:

  -d, --dos             print DOS (short) form of NAMEs (C:\PROGRA~1\)
  -m, --mixed           like --windows, but with regular slashes (C:/WINNT)
  -M, --mode            report on mode of file (binmode or textmode)
  -u, --unix            (default) print Unix form of NAMEs (/cygdrive/c/winnt)
  -w, --windows         print Windows form of NAMEs (C:\WINNT)
  -t, --type TYPE       print TYPE form: 'dos', 'mixed', 'unix', or 'windows'

Path conversion options:

  -a, --absolute        output absolute path
  -l, --long-name       print Windows long form of NAMEs (with -w, -m only)
  -p, --path            NAME is a PATH list (i.e., '/bin:/usr/bin')
  -s, --short-name      print DOS (short) form of NAMEs (with -w, -m only)
  -C, --codepage CP     print DOS, Windows, or mixed pathname in Windows
                        codepage CP.  CP can be a numeric codepage identifier,
                        or one of the reserved words ANSI, OEM, or UTF8.
                        If this option is missing, cygpath defaults to the
                        character set defined by the current locale.

System information:

  -A, --allusers        use `All Users' instead of current user for -D, -O, -P
  -D, --desktop         output `Desktop' directory and exit
  -H, --homeroot        output `Profiles' directory (home root) and exit
  -O, --mydocs          output `My Documents' directory and exit
  -P, --smprograms      output Start Menu `Programs' directory and exit
  -S, --sysdir          output system directory and exit
  -W, --windir          output `Windows' directory and exit
  -F, --folder ID       output special folder with numeric ID and exit

Other options:

  -f, --file FILE       read FILE for input; use - to read from STDIN
  -o, --option          read options from FILE as well (for use with --file)
  -c, --close HANDLE    close HANDLE (for use in captured process)
  -i, --ignore          ignore missing argument
  -h, --help            output usage information and exit
  -V, --version         output version information and exit


CLi@PC-CLI-1 ~/develop/buildroot/buildroot-2013.05/output/build/host-libtool-2.2.10
$ cygpath -u D:\tmp\tmp_dev_root\cgwin\bin\
> ^C

CLi@PC-CLI-1 ~/develop/buildroot/buildroot-2013.05/output/build/host-libtool-2.2.10
$ cygpath -u D:\tmp\tmp_dev_root\cgwin\bin
D:tmptmp_dev_rootcgwinbin

CLi@PC-CLI-1 ~/develop/buildroot/buildroot-2013.05/output/build/host-libtool-2.2.10
$ cygpath -t u D:\tmp\tmp_dev_root\cgwin\bin
Usage: cygpath (-d|-m|-u|-w|-t TYPE) [-f FILE] [OPTION]... NAME...
       cygpath [-c HANDLE]
       cygpath [-ADHOPSW]
       cygpath [-F ID]

Convert Unix and Windows format paths, or output system path information

Output type options:

  -d, --dos             print DOS (short) form of NAMEs (C:\PROGRA~1\)
  -m, --mixed           like --windows, but with regular slashes (C:/WINNT)
  -M, --mode            report on mode of file (binmode or textmode)
  -u, --unix            (default) print Unix form of NAMEs (/cygdrive/c/winnt)
  -w, --windows         print Windows form of NAMEs (C:\WINNT)
  -t, --type TYPE       print TYPE form: 'dos', 'mixed', 'unix', or 'windows'

Path conversion options:

  -a, --absolute        output absolute path
  -l, --long-name       print Windows long form of NAMEs (with -w, -m only)
  -p, --path            NAME is a PATH list (i.e., '/bin:/usr/bin')
  -s, --short-name      print DOS (short) form of NAMEs (with -w, -m only)
  -C, --codepage CP     print DOS, Windows, or mixed pathname in Windows
                        codepage CP.  CP can be a numeric codepage identifier,
                        or one of the reserved words ANSI, OEM, or UTF8.
                        If this option is missing, cygpath defaults to the
                        character set defined by the current locale.

System information:

  -A, --allusers        use `All Users' instead of current user for -D, -O, -P
  -D, --desktop         output `Desktop' directory and exit
  -H, --homeroot        output `Profiles' directory (home root) and exit
  -O, --mydocs          output `My Documents' directory and exit
  -P, --smprograms      output Start Menu `Programs' directory and exit
  -S, --sysdir          output system directory and exit
  -W, --windir          output `Windows' directory and exit
  -F, --folder ID       output special folder with numeric ID and exit
Try `cygpath --help' for more information.

CLi@PC-CLI-1 ~/develop/buildroot/buildroot-2013.05/output/build/host-libtool-2.2.10
$ cygpath -t u D:\tmp\tmp_dev_root\cgwin\bin -a
Usage: cygpath (-d|-m|-u|-w|-t TYPE) [-f FILE] [OPTION]... NAME...
       cygpath [-c HANDLE]
       cygpath [-ADHOPSW]
       cygpath [-F ID]

Convert Unix and Windows format paths, or output system path information

Output type options:

  -d, --dos             print DOS (short) form of NAMEs (C:\PROGRA~1\)
  -m, --mixed           like --windows, but with regular slashes (C:/WINNT)
  -M, --mode            report on mode of file (binmode or textmode)
  -u, --unix            (default) print Unix form of NAMEs (/cygdrive/c/winnt)
  -w, --windows         print Windows form of NAMEs (C:\WINNT)
  -t, --type TYPE       print TYPE form: 'dos', 'mixed', 'unix', or 'windows'

Path conversion options:

  -a, --absolute        output absolute path
  -l, --long-name       print Windows long form of NAMEs (with -w, -m only)
  -p, --path            NAME is a PATH list (i.e., '/bin:/usr/bin')
  -s, --short-name      print DOS (short) form of NAMEs (with -w, -m only)
  -C, --codepage CP     print DOS, Windows, or mixed pathname in Windows
                        codepage CP.  CP can be a numeric codepage identifier,
                        or one of the reserved words ANSI, OEM, or UTF8.
                        If this option is missing, cygpath defaults to the
                        character set defined by the current locale.

System information:

  -A, --allusers        use `All Users' instead of current user for -D, -O, -P
  -D, --desktop         output `Desktop' directory and exit
  -H, --homeroot        output `Profiles' directory (home root) and exit
  -O, --mydocs          output `My Documents' directory and exit
  -P, --smprograms      output Start Menu `Programs' directory and exit
  -S, --sysdir          output system directory and exit
  -W, --windir          output `Windows' directory and exit
  -F, --folder ID       output special folder with numeric ID and exit
Try `cygpath --help' for more information.

CLi@PC-CLI-1 ~/develop/buildroot/buildroot-2013.05/output/build/host-libtool-2.2.10
$

2.最后还是自己摸索出来了:

CLi@PC-CLI-1 ~/develop/buildroot/buildroot-2013.05/output/build/host-libtool-2.2.10
$ cygpath -p D:\tmp\tmp_dev_root\cgwin\bin -u
D:tmptmp_dev_rootcgwinbin

CLi@PC-CLI-1 ~/develop/buildroot/buildroot-2013.05/output/build/host-libtool-2.2.10
$ cygpath -p D:\tmp\tmp_dev_root\cgwin\bin
D:tmptmp_dev_rootcgwinbin

CLi@PC-CLI-1 ~/develop/buildroot/buildroot-2013.05/output/build/host-libtool-2.2.10
$ cygpath -p D:\tmp\tmp_dev_root\cgwin\bin -a
/cygdrive/d/tmptmp_dev_rootcgwinbin

CLi@PC-CLI-1 ~/develop/buildroot/buildroot-2013.05/output/build/host-libtool-2.2.10
$ cygpath -p "D:\tmp\tmp_dev_root\cgwin\bin" -a
/usr/bin

CLi@PC-CLI-1 ~/develop/buildroot/buildroot-2013.05/output/build/host-libtool-2.2.10
$ cygpath -p /usr/bin -a
/usr/bin

CLi@PC-CLI-1 ~/develop/buildroot/buildroot-2013.05/output/build/host-libtool-2.2.10
$ cygpath -p /usr/bin -a -w
D:\tmp\tmp_dev_root\cgwin\bin

CLi@PC-CLI-1 ~/develop/buildroot/buildroot-2013.05/output/build/host-libtool-2.2.10
$ cygpath -p "/usr/bin" -a -w
D:\tmp\tmp_dev_root\cgwin\bin

CLi@PC-CLI-1 ~/develop/buildroot/buildroot-2013.05/output/build/host-libtool-2.2.10
$ cygpath -p "D:\tmp\tmp_dev_root\cgwin\bin" -a -u
/usr/bin

CLi@PC-CLI-1 ~/develop/buildroot/buildroot-2013.05/output/build/host-libtool-2.2.10
$ cygpath -p D:\\tmp\\tmp_dev_root\\cgwin\bin -a -u
/cygdrive/d/tmp/tmp_dev_root/cgwinbin

CLi@PC-CLI-1 ~/develop/buildroot/buildroot-2013.05/output/build/host-libtool-2.2.10
$ cygpath -p D:\\tmp\\tmp_dev_root\\cgwin\bin -u
/cygdrive/d/tmp/tmp_dev_root/cgwinbin

CLi@PC-CLI-1 ~/develop/buildroot/buildroot-2013.05/output/build/host-libtool-2.2.10
$ cygpath -p D:\\tmp\\tmp_dev_root\\cgwin\\bin -a -u
/usr/bin

CLi@PC-CLI-1 ~/develop/buildroot/buildroot-2013.05/output/build/host-libtool-2.2.10
$ cygpath -p D:\\tmp\\tmp_dev_root\\cgwin\\bin -u
/usr/bin

CLi@PC-CLI-1 ~/develop/buildroot/buildroot-2013.05/output/build/host-libtool-2.2.10
$

如图:

cygpath convert windows and unix path

3.另外的那个路径:

CLi@PC-CLI-1 ~/develop/buildroot/buildroot-2013.05/output/build/host-libtool-2.2.10
$ cygpath -p "C:\Windows\system32" -a -u
/cygdrive/c/Windows/system32

【总结】

1.将Windows路径转换为unix即Linux路径:

$ cygpath -p "D:\tmp\tmp_dev_root\cgwin\bin" -a
/usr/bin

或:

$ cygpath -p D:\\tmp\\tmp_dev_root\\cgwin\\bin -a -u
/usr/bin

或:

$ cygpath -p D:\\tmp\\tmp_dev_root\\cgwin\\bin -u
/usr/bin

 

2.将Unix/Linux/Cygwin路径转换为Windows路径:

$ cygpath -p /usr/bin -a -w
D:\tmp\tmp_dev_root\cgwin\bin

或:

$ cygpath -p "/usr/bin" -a -w
D:\tmp\tmp_dev_root\cgwin\bin

 

参数解释:

  • -p==–path:表示(给定的NAME是)path路径(而不是文件)
  • -a:表示absolute,绝对路径
  • -u==–unix:表示Unix,即Linux,即Cygwin下面的路径
  • -w==-windows:表示windows路径

提示:

  • 路径是否加括号:如果是Windows中的路径,包含了反斜杠,空格(甚至是括号)等特殊字符,最好要加括号,否则,就要用反斜杠,即:
  • 要么是:"D:\tmp\tmp_dev_root\cgwin\bin"
  • 要么是:D:\\tmp\\tmp_dev_root\\cgwin\\bin


发表评论

电子邮件地址不会被公开。 必填项已用*标注

无觅相关文章插件,快速提升流量