【发布时间】:2015-05-05 03:04:43
【问题描述】:
我发生了一个奇怪的错误,如果我在 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 的cmets 的建议。不幸的是,这会产生编译器错误error: pty.h: No such file or directory。
【问题讨论】:
-
1.这根本不是c++,2.你用的是什么编译器,3.
pty.h在哪里? -
该项目将使用 C++ 这是原始骨架。这个函数openpty()需要在我们的C++项目中使用。
-
@iharob 当我包含
pty.h时,我得到另一个编译器错误:no such file or directory。我在使用 Xcode 作为我的 IDE 的 Mac OS 上