我有一个邪恶的时间试图在我的系统中找到一个错误。从字面上看开让我生气。
系统:Ubuntu 16.04 LTS,GCC&amp&amp& g 4.9,5.3 5.4可用。
本质上,我试图编译一些用于点云注册的代码,我没有更新机器,我开始看到该助推器出于某种原因已禁用了线程,从而生成了多个错误,没有找到线程库。我向后跟踪所有内容,以查看GLIB定义的Boost标头的一部分,我检查了一下,看来我的编译器在GCC或G 中看不到Unistd.h。我检查了文件,一切都在那里,但是从字面上看。我尝试使用-i标志使编译器查看目录。
示例C代码。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
int main (int argc, char *argv[])
{
int fd1;
char buf[128];
fd1 = open(argv[1], O_WRONLY | O_CREAT);
if (fd1 == -1) {
perror("File cannot be opened");
return EXIT_FAILURE;
}
scanf("%127s", buf);
write(fd1, buf, strlen(buf));
close(fd1);
return 0;
}
如果我尝试使用命令g++ test_unistd.cpp -o main
进行编译,那么我得到
/home/user/test_unistd.cpp: In function ‘int main(int, char**)’:
/home/user/test_unistd.cpp:20:32: error: ‘write’ was not declared in this scope
write(fd1, buf, strlen(buf));
^
/home/user/test_unistd.cpp:22:14: error: ‘close’ was not declared in this scope
close(fd1);
我看到的所有文件都在那里,我似乎无法弄清楚问题是什么。
写下我们在评论中发现的内容:
OP系统上的/usr/local/include/unistd.h
上有一个空文件。/usr/local
包含未托管的文件(例如,您手动安装的内容(。编译器首先检查/usr/local/include
(/usr/include
之前(,因此您可以使用它来覆盖系统功能。但是由于/usr/local/include/unistd.h
是空的,包括没有效果(除了防止使用真实的unistd.h
(。
解决方案:删除/usr/local/include/unistd.h
。这样可以再次找到/usr/include/unistd.h
的真实标头。