6

I'm running Ubuntu 18.04.1 LTS and I'm attempting to get Half Life's game libraries to run within the Xash3D engine. They build OK, but when I attempt to run the engine I get the following confusing error:

undefined symbol: _ZTVN10__cxxabiv120__si_class_type_infoE

After a bit of internet research, I gather that this basically resolves to "VTable for __cxxabiv1::__si_class_type_info". I have libc++abi-dev, libc++-dev, libc++abi1 and libc++1 installed, as well as their i386 counterparts (as I have to compile in 32-bit), so I don't know why runtime linking would fail.

In case it helps, I've found that other libraries from the Half Life repo (specifically Deathmatch Classic ones) do work. I've checked the makefiles and the DMC libraries don't have any LDFLAGS set, whereas the standard Half Life libraries use:

LDFLAGS= -lm -lstdc++

Is there any reason why I should be getting linker errors here? What can I do to fix them?

EDIT: I'm using GCC/G++ 7.3.0. If it helps, the makefiles for the libraries I'm using are here:

The one that works: https://github.com/ValveSoftware/halflife/blob/master/linux/Makefile.dmcdll

The one that doesn't: https://github.com/ValveSoftware/halflife/blob/master/linux/Makefile.hldll

I've also searched for "libc" in the *_map.txt files generated on compilation. This is what's present:

In the working DMC map file:

Archive member included to satisfy reference by file (symbol)

/usr/lib/i386-linux-gnu/libc_nonshared.a(stack_chk_fail_local.oS)
                              /home/vesper/Documents/afterburner-game/build/game/obj/dmcdll/animating.o (__stack_chk_fail_local)

As-needed library included to satisfy reference by file (symbol)

libstdc++.so.6                /home/vesper/Documents/afterburner-game/build/game/obj/dmcdll/nodes.o (operator new[](unsigned int)@@GLIBCXX_3.4)
libpthread.so.0               /usr/lib/gcc/x86_64-linux-gnu/7/32/libstdc++.so (write@@GLIBC_2.0)
libc.so.6                     /home/vesper/Documents/afterburner-game/build/game/obj/dmcdll/client.o (strcpy@@GLIBC_2.0)
/home/vesper/Documents/afterburner-game/build/game/obj/dmcdll/triggers.o: dynamic relocation against `CTriggerPush::CTriggerPush()' in read-only section `.text._Z11GetClassPtrI12CTriggerPushEPT_S2_[_Z11GetClassPtrI12CTriggerPushEPT_S2_]'

Discarded input sections

...

 .group         0x0000000000000000        0x8 /usr/lib/i386-linux-gnu/libc_nonshared.a(stack_chk_fail_local.oS)
 .text.__x86.get_pc_thunk.bx
                0x0000000000000000        0x4 /usr/lib/i386-linux-gnu/libc_nonshared.a(stack_chk_fail_local.oS)
 .note.GNU-stack
                0x0000000000000000        0x0 /usr/lib/i386-linux-gnu/libc_nonshared.a(stack_chk_fail_local.oS)

Linker script and memory map

LOAD /usr/lib/gcc/x86_64-linux-gnu/7/../../../i386-linux-gnu/crti.o
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/32/crtbeginS.o

... [Game object files] ...

LOAD /usr/lib/gcc/x86_64-linux-gnu/7/../../../i386-linux-gnu/libdl.so
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/../../../i386-linux-gnu/libpthread.so
START GROUP
LOAD /lib/i386-linux-gnu/libpthread.so.0
LOAD /usr/lib/i386-linux-gnu/libpthread_nonshared.a
END GROUP
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/../../../i386-linux-gnu/libc++abi.so
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/32/libgcc.a
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/32/libgcc_s.so
START GROUP
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/32/libgcc_s.so.1
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/32/libgcc.a
END GROUP
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/../../../i386-linux-gnu/libc.so
START GROUP
LOAD /lib/i386-linux-gnu/libc.so.6
LOAD /usr/lib/i386-linux-gnu/libc_nonshared.a
LOAD /lib/i386-linux-gnu/ld-linux.so.2
END GROUP
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/32/libgcc.a
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/32/libgcc_s.so
START GROUP
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/32/libgcc_s.so.1
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/32/libgcc.a
END GROUP
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/32/crtendS.o
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/../../../i386-linux-gnu/crtn.o

In the non-working HL map file:

Archive member included to satisfy reference by file (symbol)

/usr/lib/i386-linux-gnu/libc_nonshared.a(stack_chk_fail_local.oS)
                              /home/vesper/Documents/afterburner-game/build/game/obj/hldll/aflock.o (__stack_chk_fail_local)

As-needed library included to satisfy reference by file (symbol)

libc.so.6                     /home/vesper/Documents/afterburner-game/build/game/obj/hldll/client.o (strcpy@@GLIBC_2.0)
/home/vesper/Documents/afterburner-game/build/game/obj/hldll/egon.o: dynamic relocation against `CEgon::UpdateEffect(Vector const&, Vector const&, float)' in read-only section `.text'

...

Linker script and memory map

LOAD /usr/lib/gcc/x86_64-linux-gnu/7/../../../i386-linux-gnu/crti.o
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/32/crtbeginS.o

... [Game object files] ...

LOAD /usr/lib/gcc/x86_64-linux-gnu/7/32/libgcc.a
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/32/libgcc_s.so
START GROUP
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/32/libgcc_s.so.1
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/32/libgcc.a
END GROUP
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/../../../i386-linux-gnu/libc.so
START GROUP
LOAD /lib/i386-linux-gnu/libc.so.6
LOAD /usr/lib/i386-linux-gnu/libc_nonshared.a
LOAD /lib/i386-linux-gnu/ld-linux.so.2
END GROUP
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/32/libgcc.a
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/32/libgcc_s.so
START GROUP
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/32/libgcc_s.so.1
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/32/libgcc.a
END GROUP
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/32/crtendS.o
LOAD /usr/lib/gcc/x86_64-linux-gnu/7/../../../i386-linux-gnu/crtn.o
NoodleCollie
  • 855
  • 7
  • 24
  • `echo _ZTVN10__cxxabiv120__si_class_type_infoE | c++filt` results in `vtable for __cxxabiv1::__si_class_type_info`. Did you include `#include `? Are you mixing/matching GCC and Clang? Also see [`si_class_type_info.cc`](https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/libsupc%2B%2B/si_class_type_info.cc) source code. – jww Aug 04 '18 at 22:35
  • I'm not sure about the typeinfo include, but I would have thought that would mean the compile would fail (it succeeds on Ubuntu, and even runs properly on my Mac) - I'll check, though. AFAIK I'm not mismatching GCC and Clang, but again I'll take a look. – NoodleCollie Aug 04 '18 at 23:10
  • Please tell us exactly which version(s) of which compiler(s) you are using. – John Zwinck Aug 05 '18 at 01:18
  • Both GCC and G++ are 7.3.0. – NoodleCollie Aug 05 '18 at 09:27
  • 5
    Please don't downvote this. There is no other documentation for these kinds of errors. Following this post, I was able to resolve the same problem by adding the `-lstdc++` linker flag. – Pasha Oct 23 '18 at 18:00
  • 1
    The ``-lstdc++`` option worked well for me. – Artur Barseghyan Mar 03 '20 at 22:04
  • Thanks to @Pasha -lstdc++ works for me, too. – sailfish009 Aug 22 '20 at 08:18

1 Answers1

6

Looks like I've solved it, partially by a chance encounter with another StackOverflow comment.

Firstly, the project didn't include the linker option -Wl,--no-undefined, which would have made my life easier by not allowing the compile-time linking to complete if there were undefined symbols detected. Once I added this I noticed that there were also math library functions that couldn't be found, and I came across this answer for sqrtf undefined reference to `sqrtf' in c.

Turns out the issue was that the libraries to link against were being specified before the object files in the linker call, and one comment on the above answer pointed out that this would cause them to be ignored. I moved them to the end of the call and everything worked.

NoodleCollie
  • 855
  • 7
  • 24