This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
linking question - can objects in static archive refer to shared libs?
- From: Bahadir Balban <bahadir dot balban at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Thu, 16 Dec 2004 17:50:34 +0000
- Subject: linking question - can objects in static archive refer to shared libs?
- Reply-to: Bahadir Balban <bahadir dot balban at gmail dot com>
Hi,
I am building an executable that links with various libraries. One of
these libraries is a static one named libgfx_gtk.a. This is created
from various object files as below.
arm-linux-ar cr libgfx_gtk.a nsDrawingSurfaceGTK.o nsFontMetricsXft.o
nsRegionGTK2.o nsNativeThemeGTK.o ...
arm-linux-ranlib libgfx_gtk.a
2 of the object files above, refer to shared library symbols in
libXft.so. Objects and the archive both compile fine. Is it reasonable
to have a static archive with objects that have references to shared
symbols like this?
Because when I build an executable that links with this static
archive, I get undefined references as below:
/dist/lib/components/libgfx_gtk.a(nsFontMetricsXft.o)(.text._ZN16nsFontMetricsXft16DrawUnknownGlyphEjiiP9_XftColorP8_XftDraw+0x6c):
In function `nsFontMetricsXft::DrawUnknownGlyph(unsigned int, int,
int, _XftColor*, _XftDraw*)':
: undefined reference to `XftDrawRect'
XftDrawRect is a symbol exported from X11 library libXft.so.1.Also
note that this complaint is from the libgfx_gtk.a archive, rather than
the actual executable being linked.
Below is my command to compile my executable. What should I do to
resolve these undefined references? (My X11 libs are in a seperate
directory but normally they are successfully found by the linker)
arm-linux-gcc -I/opt/toolchain/arm-linux/local/include
-I/opt/toolchain/arm-linux/local/X11R6/include -fno-rtti
-fno-exceptions -Wall -Wconversion -Wpointer-arith -Wcast-align
-Woverloaded-virtual -Wsynth -Wno-ctor-dtor-privacy
-Wno-non-virtual-dtor -Wno-long-long -pthread -pipe -DNDEBUG
-DTRIMMED -ffunction-sections -Os
-I/opt/toolchain/arm-linux/local/include/gtk-2.0
-I/opt/toolchain/arm-linux/local/lib/gtk-2.0/include
-I/opt/toolchain/arm-linux/local/include/atk-1.0
-I/opt/toolchain/arm-linux/local/include/pango-1.0
-I/opt/toolchain/arm-linux/local/X11R6/include
-I/opt/toolchain/arm-linux/local/include/glib-2.0
-I/opt/toolchain/arm-linux/local/lib/glib-2.0/include -o
TestGtkEmbed TestGtkEmbed.o -L/opt/toolchain/arm-linux/local/lib
-L../../../../dist/bin -L../../../../dist/lib -lgtkembedmoz
-L/opt/toolchain/arm-linux/local/X11R6/lib -lX11 -ldl -lm -lsupc++
-L../../../../dist/lib/components -lcaps -lchrmlite -lcookie
-ldocshell -leditor -lembedcomponents -lgfx_gtk -lgklayout -lgkplugin
-lhtmlpars -li18n -limglib2 -ljar50 -lnecko -lnsappshell -lpref
-luconv -lwebbrwsr -lwidget_gtk2 -lxpconnect -lunicharutil_s
-lucvutil_s -ljsj -lgtkxtbin -lgfxshared_s -lgkgfx
-L../../../../dist/lib/components -L../../../../dist/lib -lmozpng
-L../../../../dist/lib -lmozjpeg -L../../../../dist/lib -lmozz
-L/opt/toolchain/arm-linux/local/X11R6/lib -lXt -lSM -lICE
-L../../../../dist/bin -lmozjs -L../../../../dist/bin -lxpcom
-L../../../../dist/bin -L/opt/mozilla_build/mozilla/dist/lib -lplds4
-lplc4 -lnspr4 -L/opt/toolchain/arm-linux/local/lib
-Wl,--export-dynamic
/opt/toolchain/arm-linux/local/X11R6/lib/libXext.so.6 -lXext
-L/opt/toolchain/arm-linux/local/lib -lgtk-x11-2.0 -lgdk-x11-2.0
-latk-1.0 -lgdk_pixbuf-2.0 -lpangox-1.0 -lpango-1.0 -lgobject-2.0
-lgmodule-2.0 -ldl -lglib-2.0 -lm
Also here is how I compile the object file with X11 symbol references.
arm-linux-gcc -o nsFontMetricsXft.o -c -DNATIVE_THEME_SUPPORT
-DXPCOM_TRANSLATE_NSGM_ENTRY_POINT=1 -DOSTYPE=\"Linux\"
-DOSARCH=\"Linux\" -I../.. -I./. -I./.. -I./../shared -I./../freetype
-I./../x11shared -I/opt/toolchain/arm-linux/local/X11R6/include
-I/opt/toolchain/arm-linux/local/X11R6/include/freetype2
-I../../../dist/include/xpcom -I../../../dist/include/string
-I../../../dist/include/widget -I../../../dist/include/view
-I../../../dist/include/util -I../../../dist/include/pref
-I../../../dist/include/uconv -I../../../dist/include/unicharutil
-I../../../dist/include/locale -I../../../dist/include/necko
-I../../../dist/include/content -I../../../dist/include/dom
-I../../../dist/include/layout -I../../../dist/include/imglib2
-I../../../dist/include/gfx -I../../../dist/include
-I/opt/mozilla_build/mozilla/dist/include/nspr
-I/opt/toolchain/arm-linux/local/X11R6/include
-I/opt/toolchain/arm-linux/local/include
-I/opt/toolchain/arm-linux/local/X11R6/include -fno-rtti
-fno-exceptions -Wall -Wconversion -Wpointer-arith -Wcast-align
-Woverloaded-virtual -Wsynth -Wno-ctor-dtor-privacy
-Wno-non-virtual-dtor -Wno-long-long -pthread -pipe -DNDEBUG
-DTRIMMED -ffunction-sections -Os
-I/opt/toolchain/arm-linux/local/include/gtk-2.0
-I/opt/toolchain/arm-linux/local/lib/gtk-2.0/include
-I/opt/toolchain/arm-linux/local/include/atk-1.0
-I/opt/toolchain/arm-linux/local/include/pango-1.0
-I/opt/toolchain/arm-linux/local/X11R6/include
-I/opt/toolchain/arm-linux/local/include/glib-2.0
-I/opt/toolchain/arm-linux/local/lib/glib-2.0/include
-I/opt/toolchain/arm-linux/local/include
-I/opt/toolchain/arm-linux/local/X11R6/include -DMOZILLA_CLIENT
-include ../../../mozilla-config.h -Wp,-MD,.deps/nsFontMetricsXft.pp
nsFontMetricsXft.cpp
Many Thanks,
Bahadir