Linkshare rotating banner
Showing posts with label coding. Show all posts
Showing posts with label coding. Show all posts

Wednesday, September 19, 2012

Setting up MinGW64 with Cygwin

This is just another version of my previous post on Cygwin with focus on MinGW64. I hope this guide will more or less make it easy to install MinGW on Windows. After following this guide, you'll be ready to develop genuine Windows applications. Just download and run setup.exe from the Cygwin website and choose the following packages.




  • bison
  • gettext-devel
  • libtool
  • make
  • mingw64-i686-gcc-g++
  • mingw64-x86_64-gcc-g++
  • patch
  • pkg-config


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



cygwin_setup_mingw64

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



cygwin_setup_dependencies

Mounting /mingw



If you're building 32-bit applications, add the following line to /etc/fstab so that /mingw is properly set up.


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


If you're building 64-bit applications, add the following line to /etc/fstab instead.


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


Creating Symbolic Links



Start the Cygwin terminal and create symbolic links to gcc and g++ in this manner.



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


Setting up environment variables



If you're building 32-bit applications, type the following commands or put them in ~/.profile:



export CC=/usr/bin/i686-w64-mingw32-gcc.exe
export CFLAGS="-mtune=pentium2 -mthreads -mms-bitfields -O2"
export CXXFLAGS="-mtune=pentium2 -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


If you're building 64-bit applications, type the following or put in ~/.profile:



export CC=/usr/bin/x86_64-w64-mingw32-gcc.exe
export CFLAGS="-mtune=core2 -mthreads -mms-bitfields -O2"
export CXXFLAGS="-mtune=core2 -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/x86_64-w64-mingw32/bin:/usr/local/bin:/usr/bin
export PKG_CONFIG_PATH=/mingw/lib/pkgconfig


For more information on possible -mtune values, look here.



Wednesday, August 19, 2009

MinGW: Posix Threads for Win32

Because a good number of software from Linux require Posix threads, porting them to a Win32 platform can be a problem as Windows is not a POSIX-compliant platform. I found an open-source project Pthreads-w32 that specifically deals with this issue. I downloaded pthreads-w32-2-8-0-release.tar.gz from the FTP site and unpacked it. Then, I issued the following command:


make clean GC-static

This produces a static library libpthreadGC2.a. I installed it by manually copying the headers and static library:


cp -iv pthread.h semaphore.h sched.h /mingw/include/
cp -iv libpthreadGC2.a /mingw/lib
cp -iv libpthreadGC2.a /mingw/lib/libpthread.a

When using the static library, don't forget to define PTW32_STATIC_LIB with CPPFLAGS.


CPPFLAGS="-DPTW32_STATIC_LIB"
export CPPFLAGS

I have yet to learn how to use this Posix thingy. I think it probably involves including the headers in my code and linking with the static library libpthread.a at the final linking stage.

Tuesday, June 30, 2009

Pexports Usage

I wanted to incorporate the following guide into my tutorial on building GTK+ for Windows, but glib had trouble picking up the libintl interface library made with pexports. So I put it here separately for reference. I'll study GCC, ld, libtool, etc. further so I can make better use of pexports.


libiconv is a character-set conversion library, and GNU gettext is a tool for localizing/translating programs. For convenience, we'll just grab precompiled packages from a GNU mirror. What we need is libiconv-1.9.1.bin.woe32.zip and gettext-runtime-0.13.1.bin.woe32.zip. Unpack them into /mingw.


cd /mingw
unzip libiconv-1.9.1.bin.woe32.zip
unzip gettext-runtime-0.13.1.bin.woe32.zip

If you don't have unzip, you can build unzip by following this post. Now we just need to create import libraries from the extracted DLL's. But first use pexports to generate *.def files:


cd /mingw
pexports -h include/iconv.h bin/iconv.dll | tr -d '@[:digit:]$' > lib/libiconv.def
pexports -h include/libintl.h bin/intl.dll | tr -d '@[:digit:]$' > lib/libintl.def

pexports can be downloaded from here. Then, run dlltool to generate import libraries like this:


cd /mingw/lib
dlltool -d libiconv.def -D iconv.dll -l libiconv.a -k
dlltool -d libintl.def -D intl.dll -l libintl.a -k


Glib Still Complaining About Gettext-Runtime?


Despite the procedure above, glib still complained about libintl when linking. The following trick will resolve the issue. Extract object codes from the interface library libintl.a into an empty directory:


mkdir /tmp/libintl
cd /tmp/libintl
ar x /mingw/lib/libintl.a

Add the object codes into libcharset.a


cd glib/libcharset/.libs
ar r libcharset.a /tmp/libintl/*.o
ranlib libcharset.a

The motive behind this trick is to let glib pick up libintl codes from another library archive libcharset.a that is used at the same time as libintl.

About This Blog

KBlog logo This blog seeks to share useful information on hottest movies available on the Internet. 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