我正在努力寻找系统中的错误。它真的让我发疯。
系统: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);
我能看到的所有文件都在那里,我似乎无法弄清楚问题所在。