LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Probleme with makefile (http://www.linuxquestions.org/questions/programming-9/probleme-with-makefile-331247/)

os2 06-07-2005 12:06 PM

Probleme with makefile
 
hi

i try to compile ipcrm.c

s
Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <libintl.h>
#include <locale.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/msg.h>
#include <sys/sem.h>
//#include "nls.h"

#if defined (__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)
/* union semun is defined by including <sys/sem.h> */
#else
/* according to X/OPEN we have to define it ourselves */
union semun {
        int val;
        struct semid_ds *buf;
        unsigned short int *array;
        struct seminfo *__buf;
};
#endif

char *execname;

typedef enum type_id {
        SHM,
        SEM,
        MSG
} type_id;

static int
remove_ids(type_id type, int argc, char **argv) {
        int id;
        int ret = 0;                /* for gcc */
        char *end;
        int nb_errors = 0;
        union semun arg;

        arg.val = 0;

        while(argc) {

                id = strtoul(argv[0], &end, 10);

                if (*end != 0) {
                        printf (("invalid id: %s\n"), argv[0]);
                        nb_errors ++;
                } else {
                        switch(type) {
                        case SEM:
                                ret = semctl (id, 0, IPC_RMID, arg);
                                break;

                        case MSG:
                                ret = msgctl (id, IPC_RMID, NULL);
                                break;
                               
                        case SHM:
                                ret = shmctl (id, IPC_RMID, NULL);
                                break;
                        }

                        if (ret) {
                                printf (("cannot remove id %s (%s)\n"),
                                        argv[0], strerror(errno));
                                nb_errors ++;
                        }
                }
                argc--;
                argv++;
        }
       
        return(nb_errors);
}

static void display_usage(void)
{
        printf (("usage: %s {shm | msg | sem} id ...\n"), execname);
}

int main(int argc, char **argv)
{
        execname = argv[0];
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR); //problem
        textdomain(PACKAGE); //problem

        if (argc < 3) {
                display_usage();
                exit(1);
        }       
        if (!strcmp(argv[1], "shm")) {
                if (remove_ids(SHM, argc-2, &argv[2])) {
                        exit(1);
                }
        }
        else if (!strcmp(argv[1], "msg")) {
                if (remove_ids(MSG, argc-2, &argv[2])) {
                        exit(1);
                }
        }
        else if (!strcmp(argv[1], "sem")) {
                if (remove_ids(SEM, argc-2, &argv[2])) {
                        exit(1);
                }
        }
        else {
                display_usage();
                printf (("unknown resource type: %s\n"), argv[1]);
                exit(1);
        }

        printf (("resource(s) deleted\n"));
        return 0;
}

i have problem where i writed: //problem

they seem to be a makefile problem...

my makefile:

Code:

CC= /opt/cross-ppc/bin/powerpc-855-linux-gnu-gcc-3.3
datadir = @datadir@
localedir = $(datadir)/locale
PROGNAME= ipcrm
INCLUDES=

STRIP=/opt/cross-ppc/bin/powerpc-855-linux-gnu-strip

DEFINES= $(INCLUDES) $(DEFS)

CFLAGS= -Os -Wall $(DEFINES)

SRCS = ipcrm.c

OBJS = ipcrm.o

.c.o:
        rm -f $@
        $(CC) $(CFLAGS) -c $*.c

all: $(PROGNAME)

$(PROGNAME) : $(OBJS)
        $(CC) $(CFLAGS) -o $(PROGNAME) $(OBJS) $(LIBS)
        $(STRIP) -s $(PROGNAME)
clean:
        rm -f $(OBJS) $(PROGNAME) core

when i compile, i get:

ipcrm.c:103: error: `PACKAGE' undeclared (first use in this function)
ipcrm.c:103: error: (Each undeclared identifier is reported only once
ipcrm.c:103: error: for each function it appears in.)
ipcrm.c:103: error: `LOCALEDIR' undeclared (first use in this function)

any idea?

thanks

rose_bud4201 06-07-2005 03:03 PM

The LOCALEDIR error is fixed by adding the following lines to the top of your makefile:

PACKAGE = @PACKAGE@
VERSION = @VERSION@
DEFS = -DLOCALEDIR=\"$(localedir)\"

I removed a "@DEFS@" from the end of the DEFS line because that was giving me undefined errors, as well.

So that it now looks like
Code:

CC= gcc
datadir = @datadir@
localedir = $(datadir)/locale
PACKAGE = @PACKAGE@
VERSION = @VERSION@
DEFS = -DLOCALEDIR=\"$(localedir)\"
PROGNAME= ipcrm
INCLUDES=

STRIP= :

DEFINES= $(INCLUDES) $(DEFS)

etc....

Fix CC and STRIP back to what you're using, I can only reproduce this on my system by using stock gcc.

The PACKAGE error isn't going to be fixed easily; the PACKAGE macro isn't defined in your makefile and I don't know how to define it and then pass it to gcc. I got around the problem by using "ipcrm" instead of PACKAGE in the .c file itself... if this isn't a viable option for you, you'll have to define the PACKAGE macro in your autoconf file or Makefile.in...I'm pretty unfamiliar with the particulars.


All times are GMT -5. The time now is 05:39 AM.