Thread: Using BSD and pty functions C++ Project

  1. #1
    Registered User
    Join Date
    Apr 2015
    Posts
    6

    Using BSD and pty functions C++ Project

    Hello

    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:

    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).

    How can I fix this error?

    Code:

    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>
        #include <pty.h> //  error: pty.h: No such file or directory
    
        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;
        }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    It might complain for C as well if you use -Wmissing-prototypes as a compiler flag.

    > #include <pty.h> // error: pty.h: No such file or directory
    Yeah, this is the real problem.

    > How can I fix this error?
    You need to find whatever package pty.h this comes in and install it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Don't forget to set your include paths--the directories where the compiler looks for these header files. How you do that depends on your compiler/IDE.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 08-02-2013, 06:45 PM
  2. College project on arrays and functions
    By jthunder in forum C Programming
    Replies: 14
    Last Post: 12-04-2011, 11:13 PM
  3. Too few arguements to functions error, c project
    By silas101 in forum C Programming
    Replies: 3
    Last Post: 11-30-2010, 04:42 AM
  4. Help with functions usage on project plz
    By LightYear in forum C Programming
    Replies: 15
    Last Post: 04-10-2010, 11:07 AM
  5. this project - functions and arrays - getting few errors
    By arps789 in forum C++ Programming
    Replies: 10
    Last Post: 12-10-2007, 08:29 PM