我有一个邪恶的时间试图找到我的系统中的错误。这实际上是 让我发疯。系统:Ubuntu 16.04 LTS,gcc & g ++ 4.9,5.3 5.4可用。任何人都有在Ubuntu上找不到unistd.h的情况?
本质上我试图为点云注册编译一些代码,我没有更新我的机器,我开始看到Boost出于某种原因禁用了线程,产生了多个错误,无法找到线程库。我回头追踪了一部分boost代码,看GLib的定义,我查了一下,似乎我的编译器在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'产生了什么? – melpomene
你得到的错误并不是说找不到'unistd.h',所以头文件出现在你的系统上。该错误表示无法找到“写入”和“关闭”功能。 – Macmade
顺便说一句,C不是C++ ...如果这是C++代码,你可能会遇到编译器寻找重载的问题...你正在传递的参数可能需要Casting ... – Macmade