Search code examples
linuxvisual-c++pngcygwinmingw

Working with VC and MinGW


I'm trying to use a few open source libraries like libpng in my VC++ project. I've used them in Linux environment without problems, but I'm clueless about how to get them to work in the VC++ environment. Here's what I tried:

  1. I installed the libpng for Win32 package from SF (I also installed zlib the same way btw). I can see png.h in Program Files\GnuWin32\include but when I include it, the compiler says it requires unistd.h. I know this is the header for POSIX system calls so Windows won't have it.

  2. I installed Cygwin, but later realized it's only good for building linux source codes on windows using gcc, instead of using MS VC (or am I wrong?)

  3. I installed MinGW, but it seems MinGW is designed for using gcc too (or am I wrong?). MinGW does come with unistd.h but this header references MinGW's sys/types.h which is from linux, and MSVC has its own different sys/types.h so the compiler doesn't know which to use. The two files define different things and neither can cover both, so including either is not enough to get the whole project compile.

To this point it seems like a quite stupid #include problem but I just can't figure out the right way to do. I'm really a cross-platfrom noob. Maybe I'm going the wrong way from beginning...

So how should I proceed? What is your standard way of using linux libraries in VC++?

By the way it is possible for me to build with gcc using MinGW or Cygwin to generate windows executables, but I'd really prefer being able to build with VC++ because of my existing code base. Thank you for any help!


Solution

  • Obviously, you must download libpng.lib/dll and header files for MS VC.

    If your package has folder structure something like GnuWin32, it is definitely not for MS VC.

    Check out OpenCV distribution (http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.2/)

    It contains VC build of libpng and other image format libraries.