LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-07-2005, 12:06 PM   #1
os2
Member
 
Registered: Dec 2003
Location: Canada
Distribution: Suse 10
Posts: 206

Rep: Reputation: 30
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
 
Old 06-07-2005, 03:03 PM   #2
rose_bud4201
Member
 
Registered: Aug 2002
Location: St Louis, MO
Distribution: Xubuntu, RHEL, Solaris 10
Posts: 927

Rep: Reputation: 30
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Probleme with thunderbird acvatiq Linux - Software 1 04-22-2005 03:08 PM
how to get (makefile -f makefile )output into the textview widget in Pygtk sailu_mvn Programming 3 02-28-2005 04:57 AM
gIFT probleme princeware Slackware 2 06-15-2004 02:19 AM
generate Makefile from Makefile.in without calling ./configure ? chris78 Programming 2 05-02-2004 01:23 PM
xinetd probleme kemu Linux - Networking 2 08-13-2003 03:14 PM


All times are GMT -5. The time now is 04:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration