tags:

views:

681

answers:

6

I'm trying to compile a C program that I downloaded off the internet using cl.exe at the command line in Windows. This file includes gnu C library files such as getopt.h and unistd.h, which are not available by default under Windows. How can I gain access to these (while still using the cl.exe compiler).

Thanks.

+2  A: 

getopt.h and unistd.h are not libraries - they are header files. Even if you had them they would be useless to you as you would also need the actual binary libraries (.LIB or .a files). The unistd.h file as its name suggests, contains declarations of functions specific specific to Unix.

anon
Is this source code simply not usable on a Windows environment, then?
Jacob Lyles
Maybe you should provide the link to the program
jitter
@Jacob It might not be. There are usually workarounds you can apply whebn going from unix to windows, but these involve you in writing some extra code.
anon
+3  A: 

For getopt.h you can use xgetopt. If you are interested in changing compilers there is always MingW. Otherwise, you'll probably have to write your own getopt.h or unistd.h.

Andrew Austin
A: 

unistd.h is standard C include file. I would be shocked if whatever compiler you are using doesn't provide it. Are you sure it isn't there?

ysth
unistd.h is not a standard C include file. I would be shocked if all compilers provided it.
anon
@Neil Butterworth: The ISO C standard is not available online, but the POSIX 1003.1 standard that's synced with it is. I gave a link to the POSIX standard defining the expected contents. If that diverged from the C standard, there is supposed to be a notation on the page - it's possible it was left out in error, I guess, but it's more likely that it is a C standard include file and MS is being obstructive and leaving it out. Where do you find the prototype for things like alarm() and unlink() if not in unistd.h?
ysth
Sorry, it is not a standard C header. alarm() and unlink() are not standard C functions (the standard analog of unlink() is remove()). Note that POSIX != ISO C.
anon
@Neil Butterworth: yes, but there are supposed to be notations like that on http://www.opengroup.org/onlinepubs/009695399/basedefs/limits.h.html where POSIX diverges.
ysth
You seem to be confusing random web pages with actual standards documents. There is certainly no ISO requirement for such notations.
anon
Amd opengroup.org (just noticed the link) is also not the ISO C standard, or anything to do with it.
anon
@Neil Butterworth: and you seem to not actually read what I say: "The ISO C standard is not available online, but the POSIX 1003.1 standard that's synced with it is. I gave a link to the POSIX standard defining the expected contents. If that diverged from the C standard, there is supposed to be a notation on the page". That is not some random website; that is the official POSIX standard, that by special arrangement with ISO includes information from the ISO C standard, despite ISO usually liking to make money off selling its standards.
ysth
+2  A: 

There's always cygwin - use the include files and link with the cygwin1.dll library, here's their FAQ entry on this.

Nikolai N Fetissov
Only do this if you can live with the rather rigorous GPL (not LGPL) strictures on using the cygwin DLL.
anon
Yeh, I'm not a huge fan of the GPL myself, but if you don't sell, or otherwise re-distribute the thing - why not?
Nikolai N Fetissov
@Nikola Agreed. And Cygwin is an easy fix, if it works. But I've given up on it because of the licence thing.
anon
Even if you are selling or redistributing, you can buy a license from RedHat.
ysth
+3  A: 

The files getopt.h and unistd.h are header files. It is better to uses a gnu compatible compiler like MINGW32. Since replacing this files is in general not enough to get your library compiling and running under a windows-compiler. If you still want to use cl.exe then replace "unistd.h" by "windows.h" and get the win32 compatible "getopt" from the internet.

bill
+1  A: 

getopt.c from MinGW will fairly trivially port to MS C (I've done this with VS2005). You can get it from the MinGW web site. This Stackoverflow posting discusses substituting for unistd.h on MS C Compilers.

ConcernedOfTunbridgeWells