I am trying to build a project on Linux via Makefile.

I keep getting cannot find <sys/time.h> error.

I asked around, and I was told that my project doesn't have access to library folders.

Therefore, I am trying to solve this problem by using the time library locally inside my project's folder. I am very new to Linux. So, please forgive my question if it sounds naive.

I found this, but I don't know what files I need, and how to build the library. http://sourceware.org/git/?p=glibc.git;a=tree;f=time;h=c950c5d4dd90541e8f3c7e1649fcde4aead989bb;hb=master

  • Where can I find the time.h library/package?
  • How do I build the library?
有帮助吗?

解决方案

On Debian-derived distributions, apt-get install libc6-dev will get the required header files. You will need them for pretty much any C project. In the general case, Debian package search or apt-file can tell you where to find missing library etc files.

其他提示

First of all, try updating your system.

sudo apt-get update 
sudo apt-get install build-essential

This should make sure you have all the libraries, proper compilers etc.

This should ideally resolve your problem.

If not, instead of doing

#include<time.h>

try doing,

#include<sys/time.h>

If this also doesn't work, then while you are compiling, use the "-lrt" flag to resolve your libraries.

Do all of these in the order listed.

time.h is a header file that belongs to the GNU C library. As a user on the system, you should have read access to header files.

To check that the header file has been installed:

find /usr/include -name time.h

If nothing is returned by the above find command, then it is likely that the GNU C library hasn't been installed. In that case, you'll have to get someone with root privileges on the box to install it (plus all dependencies) for you. If your system is Redhat-based, then you'll be interested in using yum to install the library; if on Ubuntu or Debian, you'll want to use apt.

you can try 'man time.h' for help.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top