0

I'm trying to compile static-alone x11 executable apps(apt source x11-apps).

chenli% apt source x11-apps
chenli% cd x11-apps*/xclock

chenli% make -n   
......
echo "  CC      " Clock.o;gcc -DHAVE_CONFIG_H -I.    -Wall -Wpointer-arith -Wmissing-declarations -Wformat=2 -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Wbad-function-cast -Wold-style-definition -Wdeclaration-after-statement -Wunused -Wuninitialized -Wshadow -Wcast-q
ual -Wmissing-noreturn -Wmissing-format-attribute -Wredundant-decls -Werror=implicit -Werror=nonnull -Werror=init-self -Werror=main -Werror=missing-braces -Werror=sequence-point -Werror=return-type -Werror=trigraphs -Werror=array-bounds -Werror=write-strings -Werror=address -Werror
=int-to-pointer-cast -Werror=pointer-to-int-cast -fno-strict-aliasing -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16  -g -O2 -MT Clock.o -MD -MP -MF .deps/Clock.Tpo -c -o Clock.o Clock.c
mv -f .deps/Clock.Tpo .deps/Clock.Po
echo "  CC      " xclock.o;gcc -DHAVE_CONFIG_H -I.    -Wall -Wpointer-arith -Wmissing-declarations -Wformat=2 -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Wbad-function-cast -Wold-style-definition -Wdeclaration-after-statement -Wunused -Wuninitialized -Wshadow -Wcast-
qual -Wmissing-noreturn -Wmissing-format-attribute -Wredundant-decls -Werror=implicit -Werror=nonnull -Werror=init-self -Werror=main -Werror=missing-braces -Werror=sequence-point -Werror=return-type -Werror=trigraphs -Werror=array-bounds -Werror=write-strings -Werror=address -Werro
r=int-to-pointer-cast -Werror=pointer-to-int-cast -fno-strict-aliasing -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16  -g -O2 -MT xclock.o -MD -MP -MF .deps/xclock.Tpo -c -o xclock.o xclock.c
mv -f .deps/xclock.Tpo .deps/xclock.Po
rm -f xclock
echo "  CCLD    " xclock;gcc -Wall -Wpointer-arith -Wmissing-declarations -Wformat=2 -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Wbad-function-cast -Wold-style-definition -Wdeclaration-after-statement -Wunused -Wuninitialized -Wshadow -Wcast-qual -Wmissing-noreturn -
Wmissing-format-attribute -Wredundant-decls -Werror=implicit -Werror=nonnull -Werror=init-self -Werror=main -Werror=missing-braces -Werror=sequence-point -Werror=return-type -Werror=trigraphs -Werror=array-bounds -Werror=write-strings -Werror=address -Werror=int-to-pointer-cast -We
rror=pointer-to-int-cast -fno-strict-aliasing -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16  -g -O2   -o xclock Clock.o xclock.o -lXaw7 -lXmu -lXt -lX11  -lXrender -lX11 -lXft -lxkbfile -lm 
make[2]: Leaving directory '/tmp/x11-apps-7.7+7/xclock'
make[1]: Leaving directory '/tmp/x11-apps-7.7+7/xclock'

The three gcc commands(from make -n work perfect and xclock runs successfully. But when I add -static to the last command:


chenli% ldd *.o              
Clock.o:
        not a dynamic executable
xclock.o:
        not a dynamic executable
chenli% gcc -Wall -Wpointer-arith -Wmissing-declarations -Wformat=2 -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Wbad-function-cast -Wold-style-definition -Wdeclaration-after-statement -Wunused -Wuninitialized -Wshadow -Wcast-qual -Wmissing-noreturn -Wmissing-format-attribute -Wredundant-decls -Werror=implicit -Werror=nonnull -Werror=init-self -Werror=main -Werror=missing-braces -Werror=sequence-point -Werror=return-type -Werror=trigraphs -Werror=array-bounds -Werror=write-strings -Werror=address -Werror=int-to-pointer-cast -Werror=pointer-to-int-cast -fno-strict-aliasing -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16  -g -O2   -o xclock Clock.o xclock.o -lXaw7 -lXmu -lXt -lX11  -lXrender -lX11 -lXft -lxkbfile -lm -static

......

(.text+0x60): undefined reference to `FcStrCmpIgnoreCase'
/usr/lib/gcc/sw_64sw6-sunway-linux-gnu/5.3.0/../../../sw_64-linux-gnu/libXft.a(xftstr.o): In function `_XftMatchSymbolic':
(.text+0x6c): undefined reference to `FcStrCmpIgnoreCase'
/usr/lib/gcc/sw_64sw6-sunway-linux-gnu/5.3.0/../../../sw_64-linux-gnu/libxkbfile.a(xkbbells.o): In function `XkbStdBell':
(.text+0x88): undefined reference to `XkbBell'
/usr/lib/gcc/sw_64sw6-sunway-linux-gnu/5.3.0/../../../sw_64-linux-gnu/libxkbfile.a(xkbbells.o): In function `XkbStdBell':
(.text+0x9c): undefined reference to `XkbBell'
/usr/lib/gcc/sw_64sw6-sunway-linux-gnu/5.3.0/../../../sw_64-linux-gnu/libxkbfile.a(xkbbells.o): In function `XkbStdBellEvent':
(.text+0x158): undefined reference to `XkbBellEvent'
/usr/lib/gcc/sw_64sw6-sunway-linux-gnu/5.3.0/../../../sw_64-linux-gnu/libxkbfile.a(xkbbells.o): In function `XkbStdBellEvent':
(.text+0x16c): undefined reference to `XkbBellEvent'
collect2: error: ld returned 1 exit status

I have tried add more and more lib via -lXXX to fix some errors, but still have new undefined reference pop up.

I also debted the order of libs matters https://eli.thegreenplace.net/2013/07/09/library-order-in-static-linking and Why does the order in which libraries are linked sometimes cause errors in GCC?

But gcc works fine without -static and only have errors with -static.

How can I fix this problem and why -static cause such errors?

UPDATE

I try to force gcc to use static libraries:

deepin@sw6a:~/chenli/xclock$ gcc -Wall -Wpointer-arith -Wmissing-declarations -Wformat=2 -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Wbad-function-cast -Wold-style-definition -Wdeclaration-after-statement -Wunused -Wuninitialized -Wshadow -Wcast-qual -Wmissing-noreturn -Wmissing-format-attribute -Wredundant-decls -Werror=implicit -Werror=nonnull -Werror=init-self -Werror=main -Werror=missing-braces -Werror=sequence-point -Werror=return-type -Werror=trigraphs -Werror=array-bounds -Werror=write-strings -Werror=address -Werror=int-to-pointer-cast -Werror=pointer-to-int-cast -fno-strict-aliasing -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16  -g -O2   -o xclock Clock.o xclock.o  -lXaw7  -lXmu -lXt -lX11  -l:libXrender.a -lX11 -lXft -lxkbfile -lm

But when it comes to some package like Xaw7:

chenli% gcc -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16  -g -O2   -o xclock Clock.o xclock.o /usr/lib/x86_64-linux-gnu/libXaw7.a -lXmu -lXt -lX11  -l:libXrender.a -lXft -l:libxkbfile.a -l:libm.a
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libXaw7.a(libXaw7_la-Command.o): undefined reference to symbol 'XShapeQueryExtension'
/usr/bin/ld: /lib/x86_64-linux-gnu/libXext.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

It's really wired, why static library(libXaw7.a) report undefined reference to symbol error?

Chen Li
  • 4,824
  • 3
  • 28
  • 55

0 Answers0