Linux 如何构建(获取/下载)time.h 库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11079422/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 06:54:40  来源:igfitidea点击:

How do I build (get/download) time.h library?

linuxbuildheader-filestime.h

提问by coffeenet

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

我正在尝试通过 Makefile 在 Linux 上构建一个项目。

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

我不断收到cannot find <sys/time.h>错误。

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.

因此,我试图通过在我的项目文件夹中本地使用时间库来解决这个问题。我对 Linux 很陌生。所以,如果这听起来很幼稚,请原谅我的问题。

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

我找到了这个,但我不知道我需要什么文件,以及如何构建库。 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?
  • 我在哪里可以找到 time.h 库/包?
  • 我如何建立图书馆?

采纳答案by tripleee

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

在 Debian 派生的发行版上,apt-get install libc6-dev将获得所需的头文件。几乎任何 C 项目都需要它们。在一般情况下,Debian 软件包搜索apt-file可以告诉您在哪里可以找到丢失的库等文件。

回答by lijingcheng

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

你可以试试'man time.h'寻求帮助。

回答by lijingcheng

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.

如果这也不起作用,那么在编译时,请使用“-lrt”标志来解析您的库。

Do all of these in the order listed.

按照列出的顺序执行所有这些操作。

回答by Eric Smith

time.his a header file that belongs to the GNU C library. As a user on the system, you shouldhave read access to header files.

time.h是属于 GNU C 库的头文件。作为系统上的用户,您应该具有对头文件的读取权限。

To check that the header file has been installed:

要检查头文件是否已安装:

find /usr/include -name time.h

If nothing is returned by the above findcommand, 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 yumto install the library; if on Ubuntu or Debian, you'll want to use apt.

如果上述find命令没有返回任何内容,则很可能尚未安装 GNU C 库。在这种情况下,您必须让对机器具有 root 权限的人为您安装它(以及所有依赖项)。如果您的系统是基于 Redhat 的,那么您将有兴趣使用它yum来安装该库;如果在 Ubuntu 或 Debian 上,你会想要使用apt.