Results 1 to 5 of 5

Thread: unistd.h compile error

Hybrid View

  1. #1
    shinmen14 NNTP User

    Default unistd.h compile error

    Hi ya'all i hope your having a good time. Im testing a litle program using SRGP, but im getting the following errors:

    gcc -fpcc-struct-return -I/usr/include/srgp -O2 claseuno.c \
    -L/usr/X11R6/lib -lsrgp -lX11 -lm -lpthread -unistd -o claseuno
    In file included from claseuno.c:3:
    /usr/include/unistd.h:420: error: expected declaration specifiers or ... before numeric constant
    /usr/include/unistd.h:420: error: expected declaration specifiers or ... before numeric constant
    /usr/include/unistd.h:420: error: expected declaration specifiers or ... before ( token
    make: *** [claseuno] Error 1

    Heres my code(its called claseuno.c):

    #include "srgp.h"
    #undef unsleep
    #include "unistd.h"
    #include "stdio.h"
    #include "stdlib.h"
    #include "time.h"

    void ventana(void);

    int main(void){
    pid_t t;
    int tuberia[2],n=1;
    srand(time(NULL));
    pipe(tuberia);
    t=fork();
    if(t<0){
    return 0;
    }
    if(t){
    while(1){
    printf("[%d] Escriba el valor de N:",getpid());
    scanf("%d",&n);
    write(tuberia[1],&n,sizeof(int));
    if(n==0){
    close(tuberia[1]);
    return 0;
    }
    }
    }else{
    while(1){
    read(tuberia[0],&n,sizeof(int));
    ventana();
    if(n==0){
    close(tuberia[0]);
    return 0;
    }
    }
    }
    return 0;
    }

    void ventana(void){
    deluxe_locator_measure r;
    int x,y;
    if(fork()){
    SRGP_begin("Ventana",200,200,16,0);
    SRGP_setLocatorButtonMask(LEFT_BUTTON_MASK);
    SRGP_setInputMode(LOCATOR,EVENT);
    while(1){
    x=rand()%200;
    y=rand()%200;
    SRGP_text(SRGP_defPoint(x,y),"hola");
    if(SRGP_waitEvent(6)==LOCATOR){
    SRGP_getDeluxeLocator(&r);
    SRGP_end();
    exit(0);
    }
    }
    }
    }

    and here are the lines from the make file i use to compile:

    # This sample Makefile allows you to make any SRGP application
    # whose source is exactly one .c file.
    #
    # To use this Makefile, you must type:
    #
    # make PROG=xxxx
    # ----
    # where
    # xxxx.c is the name of the file you wish to compile.
    # ----
    #
    # This is a local version which works cleanly on Linux and Unix, 6/10/2000

    CC = gcc

    GCCFLAGS = -fpcc-struct-return
    CFLAGS = -O2

    INCLUDE = -I/usr/include/srgp

    LDLIBS = -lsrgp -lX11 -lm -lpthread
    LDFLAGS = -L/usr/X11R6/lib


    $(PROG):
    $(CC) $(GCCFLAGS) $(INCLUDE) $(CFLAGS) $(PROG).c \
    $(LDFLAGS) $(LDLIBS) -o $(PROG)

    I hope you can help me,i dont know how to solve this. Anyway, if i comment the "unistd.h" include directive, and all functions related to it the error dissapears....its an open suse unistd.h wrong or what?, Thanx

  2. #2
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: unistd.h compile error

    One possibility is srgp.h contains some declarations or defines that interfere with the ones in unistd.h. Try moving the #include "srgp.h" and the #undef further down, after the system includes. It's good practice anyway.

  3. #3
    shinmen14 NNTP User

    Default Re: unistd.h compile error

    Im gonna try that ken_jap, anyway, i made it work using this strange solution that a friend told me.Its about commenting the unistd.h include directive and add this declaration:

    const unsigned short int *__ctype_b;

    Using this make this program to work with no problems. Im posting the code below ,if you wanna give it a try, im gonna try your solution anyway , thanks!.

    #include "srgp.h"
    #undef unsleep
    //#include "unistd.h"
    #include "stdio.h"
    #include "stdlib.h"
    #include "time.h"


    void ventana(void);

    const unsigned short int *__ctype_b;

    int main(void){
    pid_t t;
    int tuberia[2],n=1;
    srand(time(NULL));
    pipe(tuberia);
    t=fork();
    if(t<0){
    return 0;
    }

    if(t){
    while(1){
    printf("[%d] Escriba el valor de N:",getpid());
    scanf("%d",&n);
    write(tuberia[1],&n,sizeof(int));
    if(n==0){
    close(tuberia[1]);
    return 0;

    }
    }
    }else{
    while(1){
    read(tuberia[0],&n,sizeof(int));
    ventana();
    if(n==0){
    close(tuberia[0]);
    return 0;
    }
    }
    }
    return 0;
    }

    void ventana(void){

    deluxe_locator_measure r;
    int x,y;
    if(fork()){
    SRGP_begin("Ventana",200,200,16,0);
    SRGP_setLocatorButtonMask(LEFT_BUTTON_MASK);
    SRGP_setInputMode(LOCATOR,EVENT);
    while(1){
    x=rand()%200;

    y=rand()%200;
    SRGP_text(SRGP_defPoint(x,y),"hola");
    if(SRGP_waitEvent(6)==LOCATOR){
    SRGP_getDeluxeLocator(&r);
    SRGP_end();
    exit(0);
    }
    }
    }
    }

  4. #4
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: unistd.h compile error

    Oh dear, do I look like I have time to compile everybody's practice programs? I must act more rude in future.

  5. #5
    shinmen14 NNTP User

    Default Re: unistd.h compile error

    I solved the problem, in the line:

    #undef unsleep

    is wrong....the correct is:

    #undef usleep

    "unsleep" declaration doesnt exist neither in unistd.h, or srgp.h. Thanks for the help.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •