detailed question about X11 library

John Klinck yellowdog-general@lists.terrasoftsolutions.com
Fri Jan 24 15:17:01 2003


  I am not sure this is the right group for this question, but here goes:

  I am trying to install a graphics package from the National Center for
Atmospheric Research (NCAR), the ncar graphics library. Most of the
package installs and works except that part which displays the results. That
is, that converts the cgm graphics file to an X11 window.

  (I am using the laptop to do some work at a remote location and the
  programs I am using have a long history and have used ncar graphics for a
  while. Please don't suggest that I use another graphic package as the
  recoding time is prohibitive.)

  There are several routines that fail the compile, so I am only showing one
below (the smallest). The function open_log fails during a link to the X11
library. It is not clear in the source code why X11 is involved.  I have not
gotten the X11 source code to see where and what this is. Does anyone
recognize what this problem might be?

  I was able to install this software on YDL 2.1 (about a year ago). It also
installs on my Sun workstation running Solaris.

  Any advice or suggestions would be appreciated.


make[4]: Entering directory `/usr/local/ncarg-4.3.1/ncarview/src/bin/ctrans'
gcc -ansi  -O    -o ctrans main.o
  ../../../.././ncarview/src/lib/libctrans/libctrans.o \
  -L../../../.././ncarview/src/lib/libcgm -lcgm \
  -L../../../.././ncarview/src/lib/libncarg_ras -lncarg_ras \
  -L../../../.././common/src/libncarg_c -lncarg_c -Wl,-Bstatic \
  -L/usr/local/ncarg-4.3.1/lib -L/usr/X11R6/lib -L/usr/local/lib -lXpm -lX11 \
  -lXext    -Wl,-Bdynamic -lm 

main.o: In function `open_log':
main.o(.text+0x29c): the use of `mktemp' is dangerous, better use `mkstemp'
/usr/X11R6/lib/libX11.a(XlcDL.o): In function `try_both_dlsym':
XlcDL.o(.text+0x174): undefined reference to `dlsym'
XlcDL.o(.text+0x174): relocation truncated to fit: R_PPC_REL24 dlsym
XlcDL.o(.text+0x198): undefined reference to `dlsym'
XlcDL.o(.text+0x198): relocation truncated to fit: R_PPC_REL24 dlsym
/usr/X11R6/lib/libX11.a(XlcDL.o): In function `open_object':
XlcDL.o(.text+0x78c): undefined reference to `dlopen'
XlcDL.o(.text+0x78c): relocation truncated to fit: R_PPC_REL24 dlopen
/usr/X11R6/lib/libX11.a(XlcDL.o): In function `close_object':
XlcDL.o(.text+0x830): undefined reference to `dlclose'
XlcDL.o(.text+0x830): relocation truncated to fit: R_PPC_REL24 dlclose
collect2: ld returned 1 exit status
make[4]: *** [ctrans] Error 1
make[4]: Leaving directory `/usr/local/ncarg-4.3.1/ncarview/src/bin/ctrans'


/* 
 * $Id: main.h,v 1.4 2000/08/22 03:30:22 haley Exp $
 */
/************************************************************************
*                                                                       *
*                Copyright (C)  2000                                    *
*        University Corporation for Atmospheric Research                *
*                All Rights Reserved                                    *
*                                                                       *
* This file is free software; you can redistribute it and/or modify     *
* it under the terms of the GNU General Public License as published     *
* by the Free Software Foundation; either version 2 of the License, or  *
* (at your option) any later version.                                   *
*                                                                       *
* This software is distributed in the hope that it will be useful, but  *
* WITHOUT ANY WARRANTY; without even the implied warranty of            *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
* General Public License for more details.                              *
*                                                                       *
* You should have received a copy of the GNU General Public License     *
* along with this software; if not, write to the Free Software          *
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307   *
* USA.                                                                  *
*                                                                       *
************************************************************************/

#define	NEXT		-1
#define	DEFAULTFONT	"font1"

#ifndef TMPDIR
#define TMPDIR "/tmp"
#endif

#define TMPFILE         "/ctrans.XXXXXX"


/*
 *	$Id: main.c,v 1.39 2002/03/26 17:50:33 haley Exp $
 */
/************************************************************************
*                                                                       *
* This file is free software; you can redistribute it and/or modify     *
* it under the terms of the GNU General Public License as published     *
* by the Free Software Foundation; either version 2 of the License, or  *
* (at your option) any later version.                                   *
*                                                                       *
* This software is distributed in the hope that it will be useful, but  *
* WITHOUT ANY WARRANTY; without even the implied warranty of            *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
* General Public License for more details.                              *
*                                                                       *
* You should have received a copy of the GNU General Public License     *
* along with this software; if not, write to the Free Software         *
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307   *
* USA.                                                                  *
*                                                                       *
************************************************************************/

/***********************************************************************
*                                                                      *
*                          Copyright (C)  1990                         *
*            University Corporation for Atmospheric Research           *
*                          All Rights Reserved                         *
*                                                                      *
*                      NCAR View V3.01 - UNIX Release                  *
*                                                                      *
***********************************************************************/
/*
 *	main.c:
 *
 *
 *	Authors		John Clyne	(clyne@redcloud.ucar.edu)
 *			Tinsley Galyean	(taga@boulder.colorado.edu)
 *
 *	Date		Mon Nov 28 13:54:09 MST 1988
 *
 *	
 *		This is the main driver for ctrans. It is responsible
 *	for parsing the command line arguments, intializing ctrans
 *	and processing the named metafile.
 */

#include	<stdio.h>
#include	<stdlib.h>
#include	<ctype.h>
#include	<errno.h>
#include	<sys/types.h>
#include	<fcntl.h>
#include	<signal.h>
#include	<string.h>
#include	<ncarg/c.h>
#include	<ncarg/ctrans.h>
#include	"main.h"

#define	NCAR_REC_SIZE	1440


/*
 *	module globals for error reporting
 */
static  char    logFile[80];		/* temp log file name		*/
static	FILE	*logFP;			/* log file pointer		*/
static	boolean	doLogToFile = FALSE;	/* log messags to a temp file?	*/

static	int	eStatus;		/* exit status			*/
static	char	*progName;

extern	boolean *softFill;
extern	boolean *deBug;
extern	boolean *doBell;

static	void	open_log()
{
	(void) strcpy(logFile, TMPDIR);
	(void) strcat(logFile, TMPFILE);

	(void) mktemp(logFile);

	if ((logFP = fopen(logFile,"w")) == NULL) {
		logFP = stderr;	/* use stderr instead	*/
		fprintf(logFP, "%s: fopen(%s, w)\n", progName, logFile);
	}
	else {
		doLogToFile = TRUE;
	}
	setbuf(logFP, NULL);  /* turn off buffered i/o        */
}

static	void	close_log()
{
	int	c;

	if (doLogToFile) {
		if (logFP != stderr) (void) fclose(logFP);
		if ((logFP = fopen(logFile,"r")) == NULL) {
			logFP = stderr;	/* use stderr instead	*/
			fprintf(logFP, "%s: fopen(%s, r)\n", progName, logFile);
			return;
		}
	}

	while ((c = getc(logFP)) != EOF) {
		putc(c, stderr);
	}
	if (logFP != stderr) (void) fclose(logFP);

	doLogToFile = FALSE;
	logFP = stderr;
	(void) unlink(logFile);
	
}

static	void	log_ct(err)
	CtransRC	err;
{
	char	*s;

	while (s = ReadCtransMsg()) {
		fprintf(
			logFP, "%s: %s - %s\n", progName, 
			(err == FATAL ? "FATAL" : "WARNING"), s
		);
	}
}

static	void	cleanup(err)
	int	err;
{
	close_log();
	exit(err);
}

int	process(record, batch, sleep_time, tty, verbose, do_all)
	int		record;
	boolean		batch;
	unsigned	sleep_time;
	FILE		*tty;
	boolean		verbose;
	boolean		do_all;
{
	CtransRC	ctrc;
	static		int	frame_count = 1;
	int		status = 0;
	boolean		abort = FALSE;

	do {
		ctrc = ctrans(record);

		switch ((int) ctrc) {
		case	FATAL:
			log_ct(FATAL);
			return(-1);

		case	WARN:
			if (! opt.quiet) log_ct(WARN);
			break;

		case	OK:
			break;

		case	EOM:
			abort = TRUE;
			do_all = FALSE;
			break;
		}
	
		if (verbose  && ! abort) {
			fprintf( logFP, "plotted %d frames\n", frame_count++);
		}

		if (tty && ! abort) {
			int	c;
			while ((c = getc(tty)) != EOF) {
				if (c == '\n') break;
			}
			if (c == EOF)  return(-1);

		} else if (batch && ! abort) {
			if (sleep_time>0) sleep(sleep_time);
			CtransClear();
		}
	
	} while (do_all);

	return(status);
}

/*
 *      sigint_handler
 *
 *              interupt signal handler
 */
static	void    sigint_handler(sig)
	int	sig;
{
	close_metafile();
	close_ctrans();
	cleanup(eStatus);
}

/*
**
**	M A I N   P R O G R A M
**
*/

main(argc,argv)
int	argc;
char	**argv;
{

	char	*fcap,			/* path to font			*/
		*gcap;			/* path to device		*/
	Cgm_fd	cgm_fd;			/* CGM file descriptor		*/
	boolean batch = FALSE;		/* device library should interact
					 * with the user. Else main module
					 * is responsible for interaction
					 */
	int sleep_time = 0;	/* time to wait between displaying
					 * frames if batch is TRUE
					 */
	int	*record = NULL;		/* list of records to process	*/

					/*
					 * list of metafiles to process
					 */
	FILE	*tty = NULL;		/* tty for prompting user	*/

	char	**meta_files;
	int	i,j;
	int	od;
	CtransRC	ctrc;

	logFP = stderr;			/* log to stderr by default	*/
	progName = (progName = strrchr(argv[0], '/')) ? ++progName : *argv;

 	meta_files = (char **) malloc ((unsigned) ((argc * sizeof(char *)) +1));

	/*
	 *	parse command line argument. Separate ctrans specific
	 *	args from device specific args
	 */
	softFill = &opt.soft_fill;
	deBug = &opt.debug;
	doBell = &opt.do_bell;
	od = OpenOptionTbl();
	if (ParseOptionTable(od, &argc, argv, set_options) < 0) {
		fprintf(
			logFP, "%s : Error parsing options [ %s ]\n", 
			progName, ErrGetMsg()
		);
		cleanup(1);
	}

	/*
	 * load the options into opt
	 */
	if (GetOptions(od, get_options) < 0) {
		fprintf(
			logFP, "%s : Error getting options [ %s ]\n", 
			progName, ErrGetMsg()
		);
		PrintOptionHelp(od, logFP);
		cleanup(1);
	}

	/*
 	 * the pause option and the movie option option are mutually
	 * exclusive. ignore the movie option if both are present
	 */
	if (! opt.pause) {
		batch = opt.movie != -1;
		sleep_time = opt.movie;
	}
	else {
		/*
		 * open tty to read user prompt
		 */
		char	*tty_in = "/dev/tty";
		if (! (tty = fopen(tty_in, "r"))) {
			fprintf(
				logFP, "%s : Error opening tty(%s) [ %s ]\n",
				progName, tty_in, strerror(errno)
			);
			cleanup(1);
		}
	}

	if (opt.version) {
		PrintVersion(progName);
		cleanup(0);
	}
	if (opt.help) {
		usage(od, progName, NULL);
		cleanup(0);
	}

	/*
	 * set line scaling options
	 */
	if (opt.min_line_width > -1) 
		SetMinLineWidthDefault(opt.min_line_width);
	if (opt.max_line_width > -1) 
		SetMaxLineWidthDefault(opt.max_line_width);
	if (opt.line_scale > -1) 
		SetAdditionalLineScale(opt.line_scale);

        /*
	 *	If a device was given on command line build the full path
	 *	to it. Else try and get device from the GRAPHCAP variable
	 *	Note: if the device is a software library interface and
	 *	not a graphcap then a path will still be built to it but
	 *	it will have no meaning.
         */
        if ((gcap = getGcapname( opt.device )) == NULL ) {
		usage(od, progName, ErrGetMsg());
		cleanup(1);
	}


        /*
	 *	if a font was given on command line build the full path
	 *	to it. Else try and get font from the FONTCAP variable
	 *	Else try and use the default font
         */
        if ((fcap = getFcapname( opt.font )) == NULL) {

		/*
		 *	try to use default font
		 */
		if ((fcap = getFcapname( DEFAULTFONT )) == NULL) {
			fprintf(
				logFP,"%s: Warning - no known font [ %s ]",
				progName, ErrGetMsg()
			);
		}
        }

	/*
	 * inform ctrans to use a default color palette if one was
	 * requested
	 */
	if (opt.pal) {
		SetDefaultPalette(opt.pal);
	}

	if (!batch) (void)signal(SIGINT,&sigint_handler);


	/*
	 *	init ctrans
	 */
	if ((ctrc = init_ctrans(&argc, argv, gcap, fcap, batch)) != OK) {
		log_ct(ctrc);
		if (ctrc == FATAL) cleanup(1);
	}
	/*
	 * if graphical output is going to a tty log error messages to 
	 * a file that can be catted out later.
	 */
	if (IsOutputToTty()) {
		open_log();
	}

	/*
	 * assume everthing left in the command line is a metafile or 
	 * a record list. 
	 */
	i = 1;
	/*
	 *	look for rec list
	 */
	if (i < argc && strcmp (argv[i], "-record") == 0) {
		i++;
		j = 0;
		record = (int *) malloc ((argc + 1) * sizeof (int));
		while (IsAsciiInt(argv[i])) {

			record[j++] = atoi(argv[i++]);
		}
		record[j] = -1;
	}
			
	/*
	 * grab metafiles
	 */
	meta_files[0] = NULL;
	for (j = 0 ; i < argc; i++, j++) {
		if (*argv[i] == '-') {
			usage(od, progName, NULL);
			cleanup(1);
		} 
		else {
			meta_files[j] = argv[i];
		}
	}

	meta_files[j] = NULL;	/* terminate list	*/

	/*
	 *	if a metafile was not given read from stdin
	 */
	if (meta_files[0] == NULL) {
		meta_files[0] = "-"; meta_files[1] = NULL;
	}


	for ( ; *meta_files; meta_files++) {

		/*
		 *	open the metafile
		 */
		if ((cgm_fd = CGM_open(*meta_files, NCAR_REC_SIZE, "r")) < 0) {
			fprintf(
				logFP, "%s: Can't open metafile(%s) [ %s ]\n",
				progName, *meta_files, strerror(errno)
			);
			continue;
		}


		/* 
		 *	init the metafile we wish to process. CGM allows 
		 *	multible metafiles to reside in a single file. This 
		 *	driver will only process the first.
		 */
		ctrc = init_metafile(NEXT, cgm_fd);
		if (ctrc == FATAL) {
			(void) CGM_close(cgm_fd);
			log_ct(FATAL);
			continue;	/* skip to next metafile	*/
		}
		else if (ctrc == WARN) {
			if (! opt.quiet) log_ct(WARN);
		}

	
		if (record == NULL) {	/* process all records in file	*/
			/* 
			 *	process frames until the end of the file or an 
			 *	unrecoverable error occurs
			 */
			if (process(NEXT, batch, (unsigned) 
					sleep_time, tty, opt.verbose,TRUE) < 0){
				eStatus = 1;
			}
		}
		else {
			/* 
			 * process single frames begining at record `record`
			 */
			i = 0;
			while (record[i] != -1) {
				if (process(record[i++], batch, (unsigned) 
					sleep_time, tty, opt.verbose,FALSE)< 0){

					eStatus = 1;
				}
			}
		}

		close_metafile();
		(void) CGM_close(cgm_fd);

	}	/* while	*/

	/*
	 *	terminate ctrans
	 */
	(void) close_ctrans();

	cleanup(eStatus);
}


John M. Klinck
Center for Coastal Physical Oceanography
Department of Ocean, Earth and Atmospheric Sciences
Crittenton Hall
Old Dominion University
Norfolk, Virginia 23529
phone: 757 683-6005, fax: 757 683-5550 email: klinck@ccpo.odu.edu