Sunday, September 2, 2012

Setting Up Cygwin For C/C++ Software Development on Windows

Cygwin provides a Unix-like environment for Windows users. Cygwin is useful for people who want to learn Unix or popular Linux without having to install Unix or Linux. Cygwin can also be used to port Linux applications to Windows or develop genuine Windows applications. To install Cygwin, download setup.exe from the Cygwin website and run it.



Cygwin Packages for Software Development


In addition to the default packages, select the following packages for common development environment:


  • bison
  • gettext-devel
  • libtool
  • make
  • patch
  • pkg-config


To select a package for installation, type the name of the package in the Search box, expand the categories by clicking a plus, and clicking on the package until its version number shows up.



cygwin_setup_mingw64

If you want to develop software applications that depend on cygwin1.dll (which emulates Unix on Windows), install one of the following packages. This is when you want to port Linux applications to Windows with little modification.


  • gcc-g++

    outdated version 3.4.4
  • gcc4-g++

    GCC 4.x that links applications with cygwin1.dll


If you want to develop pure Windows applications, install one of the following packages.


  • mingw-gcc-g++

    The original MinGW compiler from mingw.org can't build 64-bit applications.
  • mingw64-i686-gcc-g++

    New MinGW compiler from mingw-w64.sourceforge.net.
  • mingw64-x86_64-gcc-g++

    Install these to develop 64-bit Windows applications.


When you see the Resolving Dependencies window, just accept and click Next.


cygwin_setup_dependencies

Setting HOME Variable


Setting the environment variable %HOME% is useful for various reasons. First of all, it allows regular users to compile freely in their user folder without requiring access to C:\Cygwin. Secondly, it allows users to save user-specific configuration in their user folder. For example, user configuration files such as .profile, .gtkrc-2.0, .fonts.conf and .pango-aliases can be saved in the folder specified by %HOME%.


Set HOME environment variable for MinGW and Cygwin

Setting Up mingw* compiler for Cygwin


The file C:\Cygwin\etc\fstab is used to set up mount points in Cygwin. If you installed mingw64 packages, open the file C:\Cygwin\etc\fstab in a text editor and append the following line.


/usr/i686-w64-mingw32/sys-root/mingw /mingw none bind

Start the Cygwin terminal and type the following commands to set up Cygwin for Windows compilation.


ln -s /usr/bin/i686-w64-mingw32-g++.exe /usr/i686-w64-mingw32/bin/g++.exe
ln -s /usr/bin/i686-w64-mingw32-gcc.exe /usr/i686-w64-mingw32/bin/gcc.exe

Also, set up some environment variables.


export CFLAGS="-march=pentium2 -mtune=i586 -mthreads -mms-bitfields -O2"
export CXXFLAGS="-march=pentium2 -mtune=i586 -mthreads -mms-bitfields -O2"
export CPPFLAGS="-I/mingw/include"
export LDFLAGS="-L/mingw/lib -Wl,--enable-auto-image-base -Wl,--enable-auto-import -Wl,--enable-runtime-pseudo-reloc"
export PATH=/mingw/bin:/usr/i686-w64-mingw32/bin:/usr/local/bin:/usr/bin
export PKG_CONFIG_PATH=/mingw/lib/pkgconfig


Setting Up gcc* Compiler for Cygwin


If you installed the gcc4 compiler (as opposed to mingw*), set up some environment variables to customize your build environment. I usually type the following commands:


CC="/usr/bin/gcc.exe"
CFLAGS="-march=pentium2 -mtune=i586 -mthreads -mms-bitfields -O2"
CPPFLAGS="-I/usr/include"
CXXFLAGS="-march=pentium2 -mtune=i586 -mthreads -mms-bitfields -O2"
LDFLAGS="-L/usr/lib -Wl,--enable-auto-image-base -Wl,--enable-auto-import -Wl,--enable-runtime-pseudo-reloc"
export CC CFLAGS CPPFLAGS CXXFLAGS LDFLAGS

No comments:

Post a Comment

About This Blog

KBlog logo This blog is about current events and issues concerning general population. Thanks for visiting the blog and posting your comments.

© Contents by KBlog

© Blogger template by Emporium Digital 2008

Followers

Total Pageviews

icon
Powered By Blogger