I have a weird error occurring, where if I use the function openpty()
in C program it compiles ok but if I have the exact same code in a C++ program I get a compiler error:
我发生了一个奇怪的错误,如果我在C程序中使用函数openpty()它编译好,但如果我在C ++程序中有完全相同的代码我得到一个编译器错误:
error: 'openpty' was not declared in this scope
Both Xcode projects have the exact same code in one file (main.c and main.cpp respectively).
两个Xcode项目在一个文件中都有完全相同的代码(分别是main.c和main.cpp)。
How can I fix this error?
我该如何解决这个错误?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <termios.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/select.h>
#include <string.h>
int main (int argc, const char * argv[]) {
int gps_fdm, gps_fds;
char slave_port_name[256];
int open_res = openpty(&gps_fdm, &gps_fds, slave_port_name, NULL, NULL); // compiler error here
return 0;
}
*Taking advice from the comments I have attempted to include pty.h
. Unfortunately this creates a compiler error error: pty.h: No such file or directory
.
*从我试图包括pty.h的评论中获取建议。不幸的是,这会产生编译器错误错误:pty.h:没有这样的文件或目录。
1 个解决方案
#1
According to the man page for openpty()
, you don't include some hypothetical "pty.h". You need to #include <util.h>
.
根据openpty()的手册页,你没有包含一些假设的“pty.h”。你需要#include
#1
According to the man page for openpty()
, you don't include some hypothetical "pty.h". You need to #include <util.h>
.
根据openpty()的手册页,你没有包含一些假设的“pty.h”。你需要#include