網路城邦
上一篇 回創作列表 下一篇   字體:
Differences between Cygwin and MinGW binaries
2007/01/24 03:22:36瀏覽1243|回應0|推薦0
It can be very easy to get confused about these two GCC targets. The binaries
for both targets are produced by GCC and execute in the Windows environment.
There are, however, significant differences that are important to understand:
  • MinGW binaries depend only on the Windows C run-time DLL and
    Win32 DLLs. Cygwin binaries depend on the Cygwin DLL and sometimes
    Win32 DLLs. The Cygwin DLL acts as a replacement for the Windows C
    run-time library.
  • Because the Windows C run-time library is substituted, Cygwin
    binaries support CR-LF, path separator, disk drive, and symbolic
    link translations. MinGW does not.
  • Cygwin binaries have access to a POSIX library and Win32 libraries.
    MinGW only has access to the Windows C run-time library and Win32
    libraries.

One should use Cygwin GCC when he:
  • wants to develop or port a UNIX tool or application to the Windows
    environment without altering too much UNIX-specific source.
  • wants to utilize the benefits of CR-LF, path separator, disk drive,
    and symbolic link translations.
  • accepts that multi-threaded binaries are not completely stable.
  • accepts that he must distribute his source code since he is required
    to do so by the GPL.

One should use MinGW GCC when he:
  • wants to develop Windows software with a free compiler suite.
  • wants to port a UNIX tool or application to the Windows environment,
    recognizing that he will have to alter UNIX-specific source code into
    Windows-compatible source code.
  • wants to produce stable multi-threaded binaries.
  • does not want to be restricted by the GPL.




Generating MinGW Binaries in a Cygwin Environment



Many times, a UNIX-based source distribution comes with 'sh' shell scripts
that are essential to the build process. The MinGW distribution does not
provide an 'sh' binary, nor does it provide various other binaries that are
likely to be called by a shell script. The Cygwin Environment does provide
the 'sh' binary as well as just about any other binary a shell script is
likely to invoke. For this reason, it is often useful to have Cygwin binaries
accessible via the PATH environment variable.



A shell script can execute in a Windows command shell as long as the
"cygwin" shell binary is explicitly invoked and the Cygwin DLL is in the
current directory or is accessible via the PATH environment variable. Of
course, if the shell script calls any other "cygwin" binaries, those binaries
must also be accessible via the PATH environment variable. The easiest way
to ensure that "cygwin" binaries are accessible is to operate from the Cygwin
bash shell. The Cygwin bash shell ensures that "cygwin" binaries are
accessible by setting the PATH environment variable appropriately. When a
command is typed in the Cygwin bash shell, the shell will check to see if
the command is a binary file or a shell script and execute it accordingly.
This advantage is not available with a Windows command shell.



When one wants to generate binaries with GCC, he can do so from any
command shell. The Cygwin bash shell is the preferred choice because of
the advantages that it brings. The Cygwin bash shell can be used to
generate both "cygwin" and "mingw" binaries. When one wants to generate
"mingw" binaries from the Cygwin bash shell, he can do so using one of
these methods:
  • Run MinGW GCC from the Cygwin bash shell.
  • Run Cygwin GCC from the Cygwin bash shell, and supply the
    -mno-cygwin switch.

The second method is possible because the original developers of Cygwin
recognized the need to produce MinGW binaries from a Cygwin Environment.
Cygwin GCC recognizes both "cygwin" and "mingw" targets. Cygwin binaries
are generated by default. MinGW binaries are generated by passing the
-mno-cygwin flag to GCC.



The second method is more useful than the first. The tools in Cygwin GCC are,
themselves, "cygwin" binaries. The tools in MinGW GCC are, themselves,
"mingw" binaries. As such, only the Cygwin GCC tools receive the special
translations support provided by the Cygwin DLL.



To better understand the Cygwin DLL advantage, consider the following
example: many times, shell scripts create symbolic links to files and
specify those symbolic links to compiler tools as parameters, e.g.
GNU Libtool. If a shell script were to provide a symbolic link to any tool
in MinGW GCC, the tool would fail. As a "mingw" binary, the tool would be
unable to resolve the symbolic link. A symbolic link is a special file that
only the Cygwin DLL is capable of creating and interpreting. Thus, if a
symbolic link were specified to a "cygwin" binary, it would be able to
interpret the link and follow it to open the correct real file.



Using the -mno-cygwin switch with Cygwin GCC in a Cygwin bash shell is the
best way to generate "mingw" binaries. The rest of this document focuses
on this method.
( 休閒生活旅人手札 )
回應 推薦文章 列印 加入我的文摘
上一篇 回創作列表 下一篇

引用
引用網址:https://classic-blog.udn.com/article/trackback.jsp?uid=keithmin&aid=679611