Subject: Need help with linking problem...
To: None <netbsd-help@netbsd.org>
From: Brian Stark <bstark@siemens-psc.com>
List: netbsd-help
Date: 10/02/1998 12:04:48
Hello,

I am having a problem linking a program with gcc (on a 1.3.2 system) and I
am hoping that someone more familar with how gcc handles linking can tell
me what is going wrong (I'm really confused...).

I'm trying to compile the GTK library (from www.gtk.org) and it has one of
those GNU-style configure scripts. That script attempts to compile a test
program and then links it to another library. The linking process is
failing and I don't understand what causes that.

This is the command that the configure script attempts to execute:

--------
gcc -o conftest -g -O2 -DGTK_NO_CHECK_CASTS -Wall -DUSE_XIM \
-I/usr/local/lib/glib/include -I/usr/local/include \
conftest.c -L/usr/local/lib  -lgmodule  -lglib
--------

When this is executed, gcc issues the following error messages:

--------
conftest.c:30: Undefined symbol `_glib_major_version' referenced from text
segment
conftest.c:30: Undefined symbol `_glib_minor_version' referenced from text
segment
conftest.c:30: Undefined symbol `_glib_micro_version' referenced from text
segment
conftest.c:34: Undefined symbol `_glib_micro_version' referenced from text
segment
conftest.c:34: Undefined symbol `_glib_minor_version' referenced from text
segment
conftest.c:34: Undefined symbol `_glib_major_version' referenced from text
segment
conftest.c:65: Undefined symbol `_glib_micro_version' referenced from text
segment
conftest.c:65: Undefined symbol `_glib_minor_version' referenced from text
segment
conftest.c:65: Undefined symbol `_glib_major_version' referenced from text
segment
--------

The undefined symbols are not undefined -- they do exist in the 'glib'
libraries (static and shared), as shown here:

--------
callisto:bstark$ nm /usr/local/lib/libglib.a | grep version
00000060 T _glib_major_version
00000068 T _glib_micro_version
00000064 T _glib_minor_version
callisto:bstark$ nm /usr/local/lib/libglib-1.1.so.3.0 | grep version
0000d354 T _glib_major_version
0000d35c T _glib_micro_version
0000d358 T _glib_minor_version
--------

I have played around with the command to compile the conftest program, and
the following two sets of commands will produce the conftest program
without error:

--------
gcc -c -g -O2 -DGTK_NO_CHECK_CASTS -Wall -DUSE_XIM \
-I/usr/local/lib/glib/include -I/usr/local/include  conftest.c
gcc -o conftest conftest.o -L/usr/local/lib -lgmodule -lglib \
/usr/local/lib/libglib.a
--------

and 

--------
gcc -static -o conftest -g -O2 -DGTK_NO_CHECK_CASTS -Wall -DUSE_XIM \
-I/usr/local/lib/glib/include -I/usr/local/include \
conftest.c -L/usr/local/lib  -lgmodule  -lglib
--------

In the first example above, I am compiling the program in two steps.
Step 1 creates the object file conftest.o, and step 2 links everything
together to form the executable. I do not understand why compiling the
program in two steps here produces a different result than attempting to
compile the program in one step like the configure script is attempting to
do.

In the second example, I am executing the same command as the configure
script, with the exception that I have added the '-static' option to
the command line. This time, the compile works and program conftest is
generated.

Ideally, I would like to use shared libraries, so I am not to thrilled
with using the -static option. Can anyone explain to me what is going on
here?

Thank you very much in advance for your help!


Brian

-------------------------------------------------------------------------
| Brian Stark                       | Internet : bstark@siemens-psc.com |
| Siemens Power Systems Control     |                                   |
| 7225 Northland Drive              | Voice    : +1 612 536-4697        |
| Brooklyn Park, MN 55428   USA     | Fax      : +1 612 536-4919        |
-------------------------------------------------------------------------