[Fwd: Re: [Image-SIG] ld problem with libImaging (solved)]

Terry Hancock hancock@anansispaceworks.com
Fri, 15 Feb 2002 14:37:00 -0800


(My solution and a diff to Makefile.in, to make this a
 little easier for the next person ;) ).  Thanks to
Chris (clee) for making it clear that this had to be
handled by changing the flag for gcc.

The problem:
Terry Hancock wrote:
> gcc -o coretest coretest.o libImaging.a -lz -ljpeg  -lm
> /usr/bin/ld: cannot find -ljpeg
> collect2: ld returned 1 exit status
> make: *** [coretest] Error 1

Was apparently caused by not being able to find the jpeg
library (which was in /usr/local/narya/lib in my case).
The only way to make this work apparently, is to provide
gcc with the -L flag, so the makefile needs a change
to reflect this.

I solved this by adding an LFLAGS variable to Makefile.in,
and referencing it in the build line, which I think is a
good solution for general use. This was really confusing.
The thing is that the linking operation doesn't use the CFLAGS
variable, and the LIBS variable is supposed to be controlled
by "configure".  So I put this in the "things configurable
but not by configure" section. Probably should really be
in configure somewhere, but that's out of my depth at present.

Diff of my solution (omitting all the stuff specific to my
system -- obviously I then changed "/usr/local/lib" to my
oddball directory "/usr/local/narya/lib"). I'd like to 
suggest adding this change to the distribution:

% diff -C3 Makefile.original Makefile.in
*** Makefile.original	Fri Feb 15 04:33:18 2002
--- Makefile.in	Fri Feb 15 04:34:08 2002
***************
*** 34,39 ****
--- 34,40 ----
  OPT=		@OPT@
  #OPT=		-g
  CFLAGS=		$(OPT) -I$(INCLDIR) -I$(JPEGINCLUDE) $(DEFS)
+ LFLAGS=         -L/usr/local/lib
  
  MKDEP=		mkdep
  SHELL=		/bin/sh
***************
*** 80,86 ****
  all:		coretest $(LIB)
  
  coretest:	coretest.o $(LIB)
! 		$(CC) -o coretest coretest.o $(LIB) $(LIBS)
  
  $(LIB):		$& $(OBJS)
  		-rm -f $(LIB)
--- 81,87 ----
  all:		coretest $(LIB)
  
  coretest:	coretest.o $(LIB)
! 		$(CC) -o coretest coretest.o $(LIB) $(LIBS) $(LFLAGS)
  
  $(LIB):		$& $(OBJS)
  		-rm -f $(LIB)


-- 
------------------------------------------------------
Terry Hancock
hancock@anansispaceworks.com       
Anansi Spaceworks                 
http://www.anansispaceworks.com 
P.O. Box 60583                     
Pasadena, CA 91116-6583
------------------------------------------------------