Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot compile C code with #include <sys/times.h> in Cygwin

Tags:

c

cygwin

I was trying to install/compile libraries such as igraph and SNAP in Windows 7 using Cygwin (and also tried MinGW-MSYS) and I ran into some problems.

I think I have narrowed down the problem to this error given by ./configure:

checking sys/times.h usability... no
checking sys/times.h presence... no
checking for sys/times.h... no

In Cygwin, /usr/include/sys/times.h actually do exists. I googled about this for MinGW and it seems that sys/times.h is not available for MinGW because "the POSIX/BSD "times" function is not part of the ANSI standard and does not exist under Mingw32 runtime".

As an experiment, I tried compiling this C code in Cygwin using gcc:

#include <stdio.h>
#include <sys/times.h>

int main (void) 
{

      return 0;
}

This does not compile, with the error sys/times.h no such file or directory. This happens even when I change the include to </usr/include/sys/times.h> or <usr/include/sys/times.h>. In the Cygwin command promot /usr/include/sys/times.h work correctly.

Question

How do I get sys/times.h usability and presence? Is there a package or library I can install?

like image 478
Legendre Avatar asked Feb 18 '23 23:02

Legendre


1 Answers

Your code compiles with no problem on my Cygwin. Actually /usr/include is one of the default include search paths for gcc, so normally gcc should be able to find sys/times.h.

Perhaps you are using MinGW version of gcc instead of Cygwin gcc? Try which gcc to make sure it's /usr/bin/gcc, and also gcc --version to make sure it does not display like mingw32-gcc.exe (GCC) x.x.x.

You can also try to compile your C file with verbose output:

gcc -v test.c

It shows how gcc searches include files. /usr/include should be one of the search path list if you use Cygwin's gcc.

like image 55
Penghe Geng Avatar answered Mar 02 '23 15:03

Penghe Geng