Subject: xforms and undefined reference to `fl_initialize'
To: None <netbsd-help@netbsd.org>
From: Jeremy C. Reed <reed@reedmedia.net>
List: netbsd-help
Date: 02/02/2001 10:00:38
I am trying to link an .a library archive file, but it doesn't seem to be
used:

 gcc -I/usr/X11R6/include/X11 -I/usr/X11R6/include -L/usr/X11R6/lib
 -lxforms -lXpm -lX11 -lm test2.c
 /tmp/ccOm4ILA.o: In function `main':
 /tmp/ccOm4ILA.o(.text+0x12): undefined reference to `fl_initialize'
 collect2: ld returned 1 exit status

 rainier:~/projects/homebsd$ cat test2.c         
 #include <forms.h>
 main (int argc, char *argv[])
 {
 
   fl_initialize(&argc, argv, 0, 0, 0);

 }

I have seen this previously when I have used newer code or headers that
didn't match up with the library.

I am using the binary distribution of xforms-088 as installed by the
NetBSD xforms package. My gcc is egcs-1.1.2; and this is under NetBSD
1.5.1_ALPHA (i386). My system is ELF and I double-checked and my system
used bxform-088-ELF.tgz.

Installed are:

/usr/X11R6/include/X11/forms.h
/usr/X11R6/lib/libforms.a
/usr/X11R6/lib/libforms.la 
/usr/X11R6/lib/libxforms.a
/usr/X11R6/lib/libxforms.la

/usr/X11R6/include/X11/forms.h:
     $Revision: 0.88 $
     $State: Beta $
     $Date: 1998/02/22 05:35:07 $
     $Author: zhao $

/usr/X11R6/lib/libforms.a:
     $State: Beta $
     $Revision: 0.88.1 $
     $Date: 1998/02/22 05:24:46 $

(libforms and libxforms are symlinked.)

I can not figure out how to get a simple C program to use this library. I
don't have an .o shared library. I tried looking at the Makefiles and
build output for lyx and dap which both use xforms for examples (and both
build successfully on my system), but I can't figure it out.

It is interesting to note that the NetBSD pkgsrc Makefile says:
"Run-time link editor tries to resolve libGL.so symbols when linking with
shared libxforms, but all the packages that requre xforms seem to work OK
without -lGL, so for now, remove the shared lib."

And then this installer does:

 /bin/rm -f  /usr/X11R6/lib/libforms.so.0.88  /usr/X11R6/lib/libforms.so.0
 /usr/X11R6/lib/libforms.so  /usr/X11R6/lib/libxforms.so.0.88
 /usr/X11R6/lib/libxforms.so.0  /usr/X11R6/lib/libxforms.so

Also, I the 'make install' says:

Libraries have been installed in:
   /usr/X11R6/lib

 If you ever happen to want to link against installed libraries
 in a given directory, LIBDIR, you must either use libtool, and
 specify the full pathname of the library, or use `-LLIBDIR'
 flag during linking and do at least one of the following:
    - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
      during execution
    - add LIBDIR to the `LD_RUN_PATH' environment variable
      during linking
    - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
    - have your system administrator add LIBDIR to `/etc/ld.so.conf'

(On a side note: should these "LIBDIR" be automatically replaced during
the pkgsrc 'make install'?)

So I tried:

 rainier:~/projects/homebsd$ gcc -I/usr/X11R6/include/X11
 -I/usr/X11R6/include -L/usr/X11R6/lib -Wl,--rpath -Wl,/usr/X11R6/lib
 test2.c
 /tmp/ccXROeII.o: In function `main':
 /tmp/ccXROeII.o(.text+0x12): undefined reference to `fl_initialize'
 collect2: ld returned 1 exit status

I guess I need to research further. (I have heard about this libtool a
lot, but I am not sure what it is. But I don't think I should need
libtool to build a simple program.)

And ideas on how I am supposed to link with this library?

(Feel free to point me to any appropriate documentation.)

Thanks,

   Jeremy C. Reed
   http://www.reedmedia.net/