views:

184

answers:

4

I would like to port a few applications that I use on Linux to Windows. In particular I have been working on wdiff. A program that compares the differences word by word of two files.

Currently I have been able to successfully compile the program on windows through Cygwin. However, I would like to run the program natively on Windows similar to the Project: UnixUtils.

How would I go about porting unix utilities on a windows environment?

My possible guess it to manually create the ./configure file so that I can create a proper makefile. Am I on the right track? Has anyone had experience porting GNU software to windows?

Update:

I've compiled it on Code::Blocks and I get two errors:

  • wdiff.c|226|error: `SIGPIPE' undeclared (first use in this function)

  • readpipe.c:71: undefined reference to `_pipe'

  • readpipe.c:74: undefined reference to `_fork

This is a linux signal that is not supported by windows... equvilancy?

  • wdiff.c|1198|error: `PRODUCT' undeclared (first use in this function)|

this is in the configure.in file... hardcode would probably be the fastest solution...

Outcome:

MSYS took care of the configure problems, however MinGW couldnt solve the posix issues. I attempt to utilize pthreads as recommended by mrjoltcola. However, after several hours I couldnt get it to compile nor link using the provided libraries. I think if this had worked it would have been the solution I was after. Special mention to Michael Madsen for MSYS.

+2  A: 

You can have a look at MinGW (and MSYS), which are similar to cygwin, but gcc produce native Windows executables. However, since the Unix emulation is not as good as cygwin, you may have to adjust your code.

Dan Andreatta
I use Code::Blocks which utilizes the MinGW compiler by default. I haven't had any luck as it relies on a large configure file. Thank you anyways though.
Shiftbit
configure scripts may surprise you and run. I'm pretty sure I accidentally ran one under powershell one time. The program didn't build, but it wouldn't surpirse me if some programs would or if in the future autoconfig works under MS Windows.
nategoose
@Shiftbit: Configure scripts are best handled using MSYS. Launch it, and you get a shell with which you can navigate to the right directory and run the script.
Michael Madsen
MSYS handled the configure, but it pukes on manual compile or make. (Errors updated in question)
Shiftbit
+1  A: 

Always try to following standarts even when porting applications. POSIX compliant compilers exist on windows/Linux. You can try mingw. It has full toolchain required to build standart POSIX application (GNU Linux as well). Check out Dev-Cpp it eases the work.

pk4r
One point, though, there is an important difference between compiling against mingw/cygwin libs and compiling a native Windows program. MinGW and Cywgin are the fastest way to get a UNIX program running, but that is not "porting". It is a layer to allow UNIX style programs to compile, and requires linking libraries that are really not needed, as Win32 has its own API equivalents.
mrjoltcola
MinGW is pretty close no? From wiki: As a consequence, a predominant feature of MinGW that may not be apparent to Open Source users at first, is that it does not use the GNU libc (C Library), but attempts to directly utilize the MS C Runtime Library (MSVCRT). Hence it aims to be as native as possible, in contrast to Cygwin.
Shiftbit
Yes, MinGW is nice. I use it over Cygwin. But to really port means writing directly to the Win32 API, imo. Example, use of CreateFile() directly instead of UNIX open(), or use of Windows threading instead of UNIX fork() (which MinGW does not support). Or the asynch winsock features that are not part of the Berkeley Socket spec. Memory mapping and threading all work differently. A native Win32 program will be a bit smaller (100-200k), and might be simpler to debug on Windows. But if I were you, I'd go MinGW until I had a good reason not to.
mrjoltcola
good point...wdiff-0.5/readpipe.c:71: undefined reference to `_pipe'wdiff/wdiff-0.5/readpipe.c:74: undefined reference to `_fork
Shiftbit
+1  A: 

Yes. If you stick to the standard C library, and POSIX functions, most is available on Windows. You may just have to find the implementations. There are implementations of things that do not require Cywgin or MinGW (such as a pthreads package, etc.)

Also, there is a great book that is written in the style of W. Richard Steven's Advanced Proramming in the UNIX Environment, and the book is Windows System Programming, author Johnson Hart. He has a 4th edition. It focuses on System Programming, there is no GUI treatment whatsoever.

http://www.amazon.com/Windows-Programming-Addison-Wesley-Microsoft-Technology/dp/0321657748

It is the best book I know of for a UNIX programming moving to Windows.

mrjoltcola
I'll try to get a hold of 'Advanced Programming in the UNIX Environment'.
Shiftbit
I was comparing to that book as the gold standard, but that book is useful for UNIX programming. For porting to Windows I was actually recommending the Windows System Programming book. But both are great to own. Good luck.
mrjoltcola
A: 

MinGW is about the easiest way to get gcc and associated binary utilities (including gdb) on a Windows PC. It includes header files and import libraries so that you can call native Windows APIs. If you want more of an integrated IDE development environment you could download Microsoft's free Visual Studio Express C++.

Either way you'll likely have to convert some of the function calls to use Windows specific APIs (if you want a book I'd also recommend the Hart book mentioned in mrjoltcola's answer). For simple command line tools this conversion is usually not a huge deal, the big porting nightmares tend to involve tools with GUIs which have deep embedded dependencies on the GUI framework provided by the OS.

Andrew O'Reilly
Meh. IMHO, the extra effort required to port a GNU || Linux application to VC++ is painful. Ugh. And the condescending error messages, like "In C, structures and unions have to contain one or more members." when it borks at something.
Lucas Jones