在C Xcode中未识别oppaty()

openpty() not recognised in C++ Xcode

本文关键字:oppaty 识别 Xcode      更新时间:2023-10-16

我发生了一个奇怪的错误,如果我在c程序中使用函数 openpty(),它会编译确定,但是如果我在C 程序中具有完全相同的代码,我会收到编译器错误:

error: 'openpty' was not declared in this scope

两个Xcode项目在一个文件中具有完全相同的代码(分别为main.c和main.cpp)。

如何解决此错误?

代码:

#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;
}

*从我试图包括pty.h的评论中获取建议。不幸的是,这创建了编译器错误error: pty.h: No such file or directory

根据 openpty()的人页面,您不包括一些假设的" pty.h"。您需要#include <util.h>