error compiling hangman example in wt with ubuntu 11.10 - wt

>g++ -o hangman hangman.C -lwthttp -lwt -lboost_signals
/tmp/cc5puOIR.o: In function `createApplication(Wt::WEnvironment const&)':
hangman.C:(.text+0x19b): undefined reference to `HangmanGame::HangmanGame(Wt::WContainerWidget*)'
/tmp/cc5puOIR.o: In function `main':
hangman.C:(.text+0x3dc): undefined reference to `Session::configureAuth()'
collect2: ld returned 1 exit status
I also tried this:
>g++ -o hangman hangman.C -I/usr/local/include -L/usr/local/lib -lwthttp -lwt -lboost_random -lboost_regex -lboost_signals -lboost_system -lboost_thread -lboost_filesystem -lboost_program_options -lboost_date_time
/usr/bin/ld: warning: libboost_program_options.so.1.46.1, needed by /usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../../lib/libwthttp.so, may conflict with libboost_program_options.so.1.49.0
/usr/bin/ld: warning: libboost_system.so.1.46.1, needed by /usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../../lib/libwthttp.so, may conflict with libboost_system.so.1.49.0
/usr/bin/ld: warning: libboost_thread.so.1.46.1, needed by /usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../../lib/libwt.so, may conflict with libboost_thread.so.1.49.0
/usr/bin/ld: warning: libboost_regex.so.1.46.1, needed by /usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../../lib/libwt.so, may conflict with libboost_regex.so.1.49.0
/usr/bin/ld: warning: libboost_signals.so.1.46.1, needed by /usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../../lib/libwt.so, may conflict with libboost_signals.so.1.49.0
/usr/bin/ld: warning: libboost_date_time.so.1.46.1, needed by /usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../../lib/libwt.so, may conflict with libboost_date_time.so.1.49.0
/usr/bin/ld: warning: libboost_filesystem.so.1.46.1, needed by /usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../../lib/libwt.so, may conflict with libboost_filesystem.so.1.49.0
/tmp/ccgojfHq.o: In function `createApplication(Wt::WEnvironment const&)':
hangman.C:(.text+0x19b): undefined reference to `HangmanGame::HangmanGame(Wt::WContainerWidget*)'
/tmp/ccgojfHq.o: In function `main':
hangman.C:(.text+0x3dc): undefined reference to `Session::configureAuth()'
collect2: ld returned 1 exit status
none worked. I have an updated boost 1_49_0 under ubuntu 11.10

hangman is not a single file example; the linker complains on a symbol that is defined in a different source (.C) file. I'm not familiar with the ubuntu install, but I guess it includes a CMakeLists.txt file that properly builds the example. If this assumption is right, you have to use cmake to create a Makefile, and then run make.

As user52875 wrote, you need to compile Session.cpp from the Auth module, or link Session.o, and probably Hangmangame.cpp too.

Related

Unable to create static binary because of undefined reference to dbus_*

I get these errors when I try to statically link my Go program that uses Gopacket:
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libpcap.a(pcap-dbus.o): in function `dbus_write':
(.text+0x103): undefined reference to `dbus_message_demarshal'
/usr/bin/ld: (.text+0x119): undefined reference to `dbus_connection_send'
/usr/bin/ld: (.text+0x122): undefined reference to `dbus_connection_flush'
/usr/bin/ld: (.text+0x12a): undefined reference to `dbus_message_unref'
/usr/bin/ld: (.text+0x178): undefined reference to `dbus_error_free'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libpcap.a(pcap-dbus.o): in function `dbus_read':
(.text+0x1c3): undefined reference to `dbus_connection_pop_message'
/usr/bin/ld: (.text+0x1e1): undefined reference to `dbus_connection_pop_message'
/usr/bin/ld: (.text+0x1f6): undefined reference to `dbus_connection_read_write'
/usr/bin/ld: (.text+0x262): undefined reference to `dbus_message_is_signal'
/usr/bin/ld: (.text+0x27f): undefined reference to `dbus_message_marshal'
/usr/bin/ld: (.text+0x2e3): undefined reference to `dbus_free'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libpcap.a(pcap-dbus.o): in function `dbus_cleanup':
(.text+0x350): undefined reference to `dbus_connection_unref'
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libpcap.a(pcap-dbus.o): in function `dbus_activate':
(.text+0x3fa): undefined reference to `dbus_connection_open'
/usr/bin/ld: (.text+0x412): undefined reference to `dbus_bus_register'
...
Indeed these symbols indeed either do not exist /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libpcap.a or show up as undefined. For example:
$ readelf -s /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libpcap.a | grep dbus_message_marshal
42: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND dbus_message_marshal
None of these functions are called from my program, but are happening because of the dependency to Gopacket.
I have libpcap installed:
$ apt list --installed|grep pcap
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
libpcap-dev/jammy,now 1.10.1-4build1 amd64 [installed]
libpcap0.8-dev/jammy,now 1.10.1-4build1 amd64 [installed]
libpcap0.8/jammy,now 1.10.1-4build1 amd64 [installed,automatic]
Is there anything else I need? Here's how I compile:
GOOS=linux CGO_ENABLED=1 go build \
-ldflags "-linkmode external -extldflags \"-static\"" \
-o bin/myprog \
-buildvcs=false
If I do not include -ldflags, the program compiles, but it is not statically linked.
I am using Go 1.18.
do not exist /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libpcap.a
They are not in libpcap. They are called by that version of libpcap.
You will have to link with all of the libraries reported by pkg-config --libs --static libdpdk in order to statically link that version of libpcap with any program whether it's in Go or not.
It's seems like it is impossible to make a statically linked binary that uses Gopacket.
I updated the build command to use libdbus-1. This got rid of the undefined dbus_* errors:
GOOS=linux CGO_ENABLED=1 CGO_LDFLAGS="-ldbus-1" go build \
-ldflags "-linkmode external -extldflags \"-static\"" \
-o bin/app \
-buildvcs=false
However, I got this error:
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libdbus-1.a(libdbus_1_la-dbus-sysdeps-unix.o): in function `_dbus_listen_systemd_sockets':
(.text+0x200e): undefined reference to `sd_listen_fds'
/usr/bin/ld: (.text+0x204f): undefined reference to `sd_is_socket'
collect2: error: ld returned 1 exit status
These functions come from libsystemd. I installed libsystemd-dev, but it seems like there is no static library for libsystemd.

gcc can't find the linking lldap libraries even with -Llibrary-path specified, why?

I have a smal testing program to test ldap. I tried to compile it on Ubuntu 19.04. I have the source file called myldaptest.c, I ran:
1.gcc -c myldaptest.c
2.gcc -L/usr/lib/x86_64-linux-gnu -lldap -llber -o myldaptest myldaptest.o
then the it complains:
/usr/bin/ld: ldapsearch-sync.o: in function main':
ldapsearch-sync.c:(.text.startup+0x236): undefined reference toldap_url_parse'
/usr/bin/ld: ldapsearch-sync.c:(.text.startup+0x30b): undefined reference to ldap_initialize'
/usr/bin/ld: ldapsearch-sync.c:(.text.startup+0x33a): undefined reference toldap_set_option'
/usr/bin/ld: ldapsearch-sync.c:(.text.startup+0x374): undefined reference to ldap_set_option'
/usr/bin/ld: ldapsearch-sync.c:(.text.startup+0x3a3): undefined reference toldap_set_option'
/usr/bin/ld: ldapsearch-sync.c:(.text.startup+0x3ea): undefined reference to ldap_set_option'
/usr/bin/ld: ldapsearch-sync.c:(.text.startup+0x422): undefined reference toldap_set_option'
...
collect2: error: ld returned 1 exit status
who can tell me why?

gcc and ld is refusing to link library statically

Just for fun (and for learning compiling in general), I gave myself the task to build a xorg-server with all libraries statically linked, except for glibc. For some reason, gcc simply ignores some of my static libraries.
When I run something like this (last 2 lines are the relevant ones):
gcc -DHAVE_DIX_CONFIG_H -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 -Wmissing-noreturn -Wmissing-format-attribute -Wredundant-decls \
-Wlogical-op -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 -fno-strict-aliasing \
-D_DEFAULT_SOURCE -D_BSD_SOURCE -DHAS_FCHOWN -DHAS_STICKY_DIR_BIT -I/usr/include/libdrm -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng16 \
-I/usr/include/X11/dri -I../../include -I../../include -I../../Xext -I../../composite -I../../damageext -I../../xfixes -I../../Xi -I../../mi -I../../miext/sync \
-I../../miext/shadow -I../../miext/damage -I../../render -I../../randr -I../../fb -I../../dbe -I../../present -fvisibility=hidden -DHAVE_XORG_CONFIG_H \
-fvisibility=hidden -I/usr/include/libdrm -g -O2 -pthread -o Xorg sdksyms.o \
/lib/arm-linux-gnueabihf/libz.a ../../dix/.libs/libmain.a ../../dix/.libs/libdix.a loader/.libs/libloader.a common/.libs/libcommon.a os-support/.libs/libxorgos.a \
parser/.libs/libxf86config.a dixmods/.libs/libdixmods.a modes/.libs/libxf86modes.a ramdac/.libs/libramdac.a ddc/.libs/libddc.a i2c/.libs/libi2c.a \
../../composite/.libs/libcomposite.a ../../xfixes/.libs/libxfixes.a ../../Xext/.libs/libXext.a ../../dbe/.libs/libdbe.a ../../record/.libs/librecord.a \
../../randr/.libs/librandr.a ../../render/.libs/librender.a ../../damageext/.libs/libdamageext.a ../../present/.libs/libpresent.a \
../../miext/damage/.libs/libdamage.a ../../Xi/.libs/libXi.a ../../xkb/.libs/libxkb.a xkb/.libs/libxorgxkb.a dri/.libs/libdri.a dri2/.libs/libdri2.a \
../../dri3/.libs/libdri3.a ../../glx/.libs/libglxvnd.a ../../miext/sync/.libs/libsync.a ../../mi/.libs/libmi.a ../../os/.libs/libos.a -lcrypto \
../../Xext/.libs/libXvidmode.a \
-Wl,-Bstatic -lpciaccess -ldrm -lpixman-1 -lXau -lxshmfence -lm -lbz2 -lfontenc -ludev \
-Wl,-Bdynamic -lXdmcp -lXfont2 -lrt -ldl -lpthread
It produces a binary with the following links:
(sid)root#localhost:/opt/xorg-server-1.20.5/hw/xfree86# ldd Xorg
libcrypto.so.1.1 => /lib/arm-linux-gnueabihf/libcrypto.so.1.1 (0xf6a8b000)
libXdmcp.so.6 => /lib/arm-linux-gnueabihf/libXdmcp.so.6 (0xf6a77000)
libXfont2.so.2 => /lib/arm-linux-gnueabihf/libXfont2.so.2 (0xf6a4b000)
librt.so.1 => /lib/arm-linux-gnueabihf/librt.so.1 (0xf6a35000)
libdl.so.2 => /lib/arm-linux-gnueabihf/libdl.so.2 (0xf6a22000)
libpthread.so.0 => /lib/arm-linux-gnueabihf/libpthread.so.0 (0xf69fd000)
libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0xf6902000)
/lib/ld-linux-armhf.so.3 (0xf6ec7000)
libbsd.so.0 => /lib/arm-linux-gnueabihf/libbsd.so.0 (0xf68df000)
libz.so.1 => /lib/arm-linux-gnueabihf/libz.so.1 (0xf68bc000)
libbz2.so.1.0 => /lib/arm-linux-gnueabihf/libbz2.so.1.0 (0xf68a0000)
libm.so.6 => /lib/arm-linux-gnueabihf/libm.so.6 (0xf6837000)
libfontenc.so.1 => /lib/arm-linux-gnueabihf/libfontenc.so.1 (0xf6822000)
libfreetype.so.6 => /lib/arm-linux-gnueabihf/libfreetype.so.6 (0xf67a2000)
libpng16.so.16 => /lib/arm-linux-gnueabihf/libpng16.so.16 (0xf6770000)
As seen on the output, "libz" is dynamically linked. So I thought I would try to force gcc/ld to use the static libz instead. But nothing works. I have tried adding "-lz" to the -Bstatic list and I have also tried with "-l:libz.a", as well as with the full path to the file "/lib/arm-linux-gnueabihf/libz.a". Nothing works and the final binary still links to the dymanic .so library. gcc does not give me any errors, it simply seem to ignore my request of statically linking some libraries.
What am I doing wrong?
Also, when I move the two libraries "-lXdmcp -lXfont2" from the dynamic list to the static list, gcc fails with some errors that looks like the libraries are referencing things that is not included? How would I debug linking problems like that?
/usr/bin/ld: /usr/lib/gcc/arm-linux-gnueabihf/9/../../../arm-linux-gnueabihf/libXdmcp.a(Key.o): in function `XdmcpGenerateKey':
(.text+0x2): undefined reference to `arc4random_buf'
/usr/bin/ld: /usr/lib/gcc/arm-linux-gnueabihf/9/../../../arm-linux-gnueabihf/libXfont2.a(ftfuncs.o): in function `sfnt_get_ushort':
(.text+0x1a): undefined reference to `FT_Load_Sfnt_Table'
/usr/bin/ld: /usr/lib/gcc/arm-linux-gnueabihf/9/../../../arm-linux-gnueabihf/libXfont2.a(ftfuncs.o): in function `FreeTypeFreeFace.part.3':
(.text+0x412): undefined reference to `FT_Done_Face'
/usr/bin/ld: /usr/lib/gcc/arm-linux-gnueabihf/9/../../../arm-linux-gnueabihf/libXfont2.a(ftfuncs.o): in function `FreeTypeFreeFont':
(.text+0x4aa): undefined reference to `FT_Done_Size'
/usr/bin/ld: /usr/lib/gcc/arm-linux-gnueabihf/9/../../../arm-linux-gnueabihf/libXfont2.a(ftfuncs.o): in function `FreeTypeActivateInstance':
(.text+0x686): undefined reference to `FT_Activate_Size'
/usr/bin/ld: (.text+0x6b4): undefined reference to `FT_Set_Transform'
/usr/bin/ld: /usr/lib/gcc/arm-linux-gnueabihf/9/../../../arm-linux-gnueabihf/libXfont2.a(ftfuncs.o): in function `FreeTypeLoadFont':
(.text+0x8f8): undefined reference to `FT_Get_Sfnt_Table'
/usr/bin/ld: (.text+0xb6e): undefined reference to `FT_Get_PS_Font_Info'
/usr/bin/ld: (.text+0xc7c): undefined reference to `FT_New_Size'
/usr/bin/ld: (.text+0xcb8): undefined reference to `FT_Set_Char_Size'
/usr/bin/ld: (.text+0xcc6): undefined reference to `FT_Done_Size'
/usr/bin/ld: (.text+0xe70): undefined reference to `FT_Set_Pixel_Sizes'
/usr/bin/ld: /usr/lib/gcc/arm-linux-gnueabihf/9/../../../arm-linux-gnueabihf/libXfont2.a(ftfuncs.o): in function `FT_Do_SBit_Metrics.isra.6':
(.text+0xf9c): undefined reference to `FT_Set_Pixel_Sizes'
/usr/bin/ld: (.text+0xfaa): undefined reference to `FT_Load_Glyph'
/usr/bin/ld: /usr/lib/gcc/arm-linux-gnueabihf/9/../../../arm-linux-gnueabihf/libXfont2.a(ftfuncs.o): in function `ft_get_very_lazy_bbox':
(.text+0x10a4): undefined reference to `FT_Load_Sfnt_Table'
/usr/bin/ld: (.text+0x10d8): undefined reference to `FT_MulFix'
/usr/bin/ld: (.text+0x10e8): undefined reference to `FT_MulFix'
/usr/bin/ld: (.text+0x10f2): undefined reference to `FT_MulFix'
/usr/bin/ld: (.text+0x10fc): undefined reference to `FT_MulFix'
/usr/bin/ld: (.text+0x116a): undefined reference to `FT_Vector_Transform'
/usr/bin/ld: (.text+0x1172): undefined reference to `FT_Vector_Transform'
/usr/bin/ld: (.text+0x117a): undefined reference to `FT_Vector_Transform'
/usr/bin/ld: (.text+0x1182): undefined reference to `FT_Vector_Transform'
/usr/bin/ld: /usr/lib/gcc/arm-linux-gnueabihf/9/../../../arm-linux-gnueabihf/libXfont2.a(ftfuncs.o): in function `FreeTypeRasteriseGlyph':
(.text+0x1530): undefined reference to `FT_Outline_Get_BBox'
/usr/bin/ld: (.text+0x1704): undefined reference to `FT_Outline_Get_BBox'
/usr/bin/ld: (.text+0x17d0): undefined reference to `FT_Load_Glyph'
/usr/bin/ld: (.text+0x1810): undefined reference to `FT_Outline_Get_BBox'
/usr/bin/ld: (.text+0x1c56): undefined reference to `FT_Load_Glyph'
/usr/bin/ld: (.text+0x1d0e): undefined reference to `FT_Render_Glyph'
/usr/bin/ld: (.text+0x1dd0): undefined reference to `FT_Outline_Get_BBox'
/usr/bin/ld: /usr/lib/gcc/arm-linux-gnueabihf/9/../../../arm-linux-gnueabihf/libXfont2.a(ftfuncs.o): in function `FreeTypeLoadXFont':
(.text+0x3042): undefined reference to `FT_New_Face'
/usr/bin/ld: (.text+0x3088): undefined reference to `FT_Init_FreeType'
/usr/bin/ld: (.text+0x33f6): undefined reference to `FT_Get_Sfnt_Table'
/usr/bin/ld: (.text+0x3af0): undefined reference to `FT_Get_Sfnt_Table'
/usr/bin/ld: (.text+0x3afc): undefined reference to `FT_Get_Sfnt_Table'
/usr/bin/ld: (.text+0x3b08): undefined reference to `FT_Get_PS_Font_Info'
/usr/bin/ld: (.text+0x3e8a): undefined reference to `FT_Get_Postscript_Name'
/usr/bin/ld: (.text+0x3f04): undefined reference to `FT_Get_X11_Font_Format'
/usr/bin/ld: /usr/lib/gcc/arm-linux-gnueabihf/9/../../../arm-linux-gnueabihf/libXfont2.a(fttools.o): in function `FTGetName':
(.text+0x22): undefined reference to `FT_Get_Sfnt_Name_Count'
/usr/bin/ld: (.text+0x40): undefined reference to `FT_Get_Sfnt_Name'
/usr/bin/ld: /usr/lib/gcc/arm-linux-gnueabihf/9/../../../arm-linux-gnueabihf/libXfont2.a(gunzip.o): in function `BufZipFileClose':
(.text+0x48): undefined reference to `inflateEnd'
/usr/bin/ld: /usr/lib/gcc/arm-linux-gnueabihf/9/../../../arm-linux-gnueabihf/libXfont2.a(gunzip.o): in function `BufZipFileFill':
(.text+0xcc): undefined reference to `inflate'
/usr/bin/ld: /usr/lib/gcc/arm-linux-gnueabihf/9/../../../arm-linux-gnueabihf/libXfont2.a(gunzip.o): in function `BufFilePushZIP':
(.text+0x1cc): undefined reference to `inflateInit2_'
/usr/bin/ld: /usr/lib/gcc/arm-linux-gnueabihf/9/../../../arm-linux-gnueabihf/libXfont2.a(bunzip2.o): in function `BufBzip2FileClose':
(.text+0x48): undefined reference to `BZ2_bzDecompressEnd'
/usr/bin/ld: /usr/lib/gcc/arm-linux-gnueabihf/9/../../../arm-linux-gnueabihf/libXfont2.a(bunzip2.o): in function `BufBzip2FileFill':
(.text+0xce): undefined reference to `BZ2_bzDecompress'
/usr/bin/ld: /usr/lib/gcc/arm-linux-gnueabihf/9/../../../arm-linux-gnueabihf/libXfont2.a(bunzip2.o): in function `BufFilePushBZIP2':
(.text+0x1c2): undefined reference to `BZ2_bzDecompressInit'
/usr/bin/ld: /usr/lib/gcc/arm-linux-gnueabihf/9/../../../arm-linux-gnueabihf/libXfont2.a(ftenc.o): in function `FTPickMapping':
(.text+0x20): undefined reference to `FontEncFromXLFD'
/usr/bin/ld: (.text+0x68): undefined reference to `FT_Get_BDF_Charset_ID'
/usr/bin/ld: (.text+0xd0): undefined reference to `FT_Get_BDF_Charset_ID'
/usr/bin/ld: (.text+0xe2): undefined reference to `FT_Select_Charmap'
/usr/bin/ld: (.text+0xf4): undefined reference to `FontEncFind'
/usr/bin/ld: (.text+0x10a): undefined reference to `FontEncFind'
/usr/bin/ld: (.text+0x118): undefined reference to `FT_Has_PS_Glyph_Names'
/usr/bin/ld: (.text+0x18c): undefined reference to `FT_Get_BDF_Charset_ID'
/usr/bin/ld: (.text+0x19c): undefined reference to `FontEncFind'
/usr/bin/ld: (.text+0x242): undefined reference to `FontEncFind'
/usr/bin/ld: (.text+0x282): undefined reference to `FT_Get_Sfnt_Table'
/usr/bin/ld: /usr/lib/gcc/arm-linux-gnueabihf/9/../../../arm-linux-gnueabihf/libXfont2.a(ftenc.o): in function `FTRemap':
(.text+0x2d6): undefined reference to `FontEncName'
/usr/bin/ld: (.text+0x2ea): undefined reference to `FontEncRecode'
/usr/bin/ld: (.text+0x2f6): undefined reference to `FT_Set_Charmap'
/usr/bin/ld: (.text+0x316): undefined reference to `FT_Set_Charmap'
/usr/bin/ld: (.text+0x2e6): undefined reference to `FT_Get_Name_Index'
/usr/bin/ld: (.text+0x304): undefined reference to `FT_Get_Char_Index'
/usr/bin/ld: (.text+0x326): undefined reference to `FT_Get_Char_Index'
collect2: error: ld returned 1 exit status
Short Answer: If you opt for static libraries (assuming that there are ".a" available), the order of the libraries matter - on the command line matter !
Long Answer:
If you have two libraries (A, B) linked with the main (M) code, where there are calls M->A, and A->B, you have to specify the libraries in that order: M, A, B. Recall that when a static library is referenced, the linker will attempt to look for any unresolved reference (function, variable, method, ...) in the named library, and extract the only the '.o' files that resolve those references from the '.a' into the executable.
If the libraries are specified as M, B, A, the linker will look into library 'B' and will not identify any '.o' to be included (since there is only reference M->A). It will then retrieve the '.o' from the A library to satisfy the call M->A, and report error on the newly discovered calls A->B.
When using shared-objects, the whole '.so' is linked (by reference), and all globally defined symbols in the '.so' will be available to any module in the executable, including modules linked from other .so. Therefore, the order of specifying '.so' will usually not matter
it simply seem to ignore my request of statically linking some
libraries.
Unlikely per se.
What am I doing wrong?
You are misunderstanding the nature of dynamic linking. At least these factors are in play:
The shared objects you are linking in may have their own dependencies on other dynamic objects.
Depending on platform and implementation details, the link may well succeed even though some of the dynamic objects' own dependencies are not resolved by anything named on the command line.
The static libraries you are linking very likely do not provide viable resolutions for anything in any of the dynamic libraries.
The overall dynamic dependencies of a program, such as are presented by ldd, is the transitive closure of the dependencies of all shared objects involved. They are not necessarily all referenced directly by the SO that contains the program entry point, and they could even change over time if shared library implementations are swapped out.
Bottom line: it is very likely that at least some of your unexpected dynamic dependencies are coming from the shared objects you are linking, probably libXdmcp and libXfont2. The static libraries are linked, and they will be used to resolve symbols in the main program and in static libraries preceding them on the command line, but they cannot satisfy the shared objects' references to dynamic symbols, no matter where anything appears on the command line.
Also, when I move the two libraries "-lXdmcp -lXfont2" from the
dynamic list to the static list, gcc fails with some errors that looks
like the libraries are referencing things that is not included? How
would I debug linking problems like that?
Static libraries need to be ordered correctly on the link command line. Each one must precede the (static) libraries containing symbols they need, so these particular ones probably need to appear near the front. If necessary, you may repeat libraries on the command line, which is useful if you have circular dependencies, or can serve as a quick hack if you're having trouble finding a viable order otherwise.
You would debug by figuring out with library does provide the symbols the linker complains about, and which library references each. This tells you about the necessary command-line ordering.

/usr/bin/ld: cannot find -lmemcached_gem

While trying to make the memcached gem, i am getting the following error:
*linking shared-object rlibmemcached.so
/usr/bin/ld: skipping incompatible /ghostcache/nightly_build/components/ruby-memcached/akamai/ruby-memcached/memcached-1.8.0/ext/lib/libmemcached_gem.a when searching for -lmemcached_gem
/usr/bin/ld: skipping incompatible /ghostcache/nightly_build/components/ruby-memcached/akamai/ruby-memcached/memcached-1.8.0/ext/lib/libmemcached_gem.a when searching for -lmemcached_gem
/usr/bin/ld: cannot find -lmemcached_gem
collect2: ld returned 1 exit status
make[2]: *** [rlibmemcached.so] Error 1*
Looks like there is some platform issue. The libmemcached_gem.a library does exist in that path. I tried building by passing -m32 and -m64, but it fails for the same reason.
Any help will be much appreciated.

Cannot find crtn.o, linking 32 bit code on 64 bit system

I'm attempting to assemble some 32-bit code using NASM and GCC on a 64-bit system. I use the following two commands
nasm -f elf32 -g -F stabs coc.asm
gcc -m32 -o coc coc.o
NASM appears to do fine, but LD complains:
/usr/bin/ld: cannot find crt1.o: No such file or directory
/usr/bin/ld: cannot find crti.o: No such file or directory
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6.1/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6.1/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: cannot find -lc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6.1/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6.1/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: cannot find crtn.o: No such file or directory
collect2: ld returned 1 exit status
I'm running Ubuntu 11.10, and I checked and I'm pretty sure libc is installed.
You are not assembling, but linking an executable, which needs OS startup files.
It seems you don't have gcc-*-multilib installed, which contains the necessary files: http://packages.ubuntu.com/oneiric/amd64/gcc-4.6-multilib/filelist
You need to install gcc-multilib to get the proper 32-Bit lib
I had a very similar problem on ubuntu 11.10. See my question on SO about this. What helped for me, was linking the crt*.o to /lib/. After that I never had other problems with this issue. A bit more of a cludge, but for me it solved the problems.

Resources