【发布时间】:2017-05-30 19:33:09
【问题描述】:
我正忙着寻找系统中的错误。从字面上看 快把我逼疯了。
系统:Ubuntu 16.04 LTS、gcc&g++ 4.9、5.3 5.4 可用。
基本上我试图编译一些用于点云注册的代码,我没有更新我的机器,我开始看到 Boost 出于某种原因禁用了线程,产生了多个无法找到线程库的错误。我将所有内容回溯到查看 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);
我能看到的所有文件都在那里,我似乎无法弄清楚问题所在。
【问题讨论】:
-
g++ -E test_unistd.cpp -o test_unistd.i产生什么? -
你得到的错误并不是说没有找到
unistd.h,所以你的系统上存在标题。错误提示找不到write和close函数。 -
为什么在
/usr/local/include/unistd.h有一个文件?里面有什么? -
您呈现的错误信息与您呈现的代码无关。行号错误。我们感谢您尝试提供一个最小的示例,但它还需要是可验证的(这个不是),并且是完整的(我怀疑这个不是)。
-
@EvanO'Keeffe 不要复制
/usr/include/unistd.h,只需删除/usr/local中的文件。