Daemon icon indicating copy to clipboard operation
Daemon copied to clipboard

Make sure libz and librt are found when building against deps libraries instead of system ones

Open illwieckz opened this issue 1 year ago • 3 comments

Make sure libz and librt are found when building against deps libraries instead of system ones.

It looks like it only worked because we were lucky some system libraries brought the flags. For example system freetype2 pkg-config likely set -lz, so we had it when building the game even if the CMake code didn't looked for zlib when building the game code. Something similar probably happened with the -lrt flag.

Fixes missing librt:

/usr/i686-linux-gnu/bin/ld: libsrclibs-mumblelink.a(libmumblelink.cpp.o): undefined reference to symbol 'shm_open@@GLIBC_2.2'
/usr/i686-linux-gnu/bin/ld: /lib/i386-linux-gnu/librt.so.1: error adding symbols: DSO missing from command line
/usr/i686-linux-gnu/bin/ld: libsrclibs-nacl-native.a(nacl_imc_posix.cc.o): in function `TryShmOrTempOpen(unsigned int, char const*, bool) [clone .constprop.0]':
Unvanquished/daemon/libs/nacl/native_client/src/shared/imc/posix/nacl_imc_posix.cc:128: undefined reference to `shm_open'
/usr/i686-linux-gnu/bin/ld: Unvanquished/daemon/libs/nacl/native_client/src/shared/imc/posix/nacl_imc_posix.cc:135: undefined reference to `shm_unlink'

Fix missing libz:

/usr/i686-linux-gnu/bin/ld: build/deps/linux-i686-default_9/lib/libfreetype.a(ftgzip.o): in function `ft_gzip_stream_close':
ftgzip.c:(.text+0x1d3): undefined reference to `inflateEnd'
/usr/i686-linux-gnu/bin/ld: build/deps/linux-i686-default_9/lib/libfreetype.a(ftgzip.o): in function `ft_gzip_file_fill_output':
ftgzip.c:(.text+0x2f9): undefined reference to `inflate'
/usr/i686-linux-gnu/bin/ld: build/deps/linux-i686-default_9/lib/libfreetype.a(ftgzip.o): in function `ft_gzip_file_io':
ftgzip.c:(.text+0x5fb): undefined reference to `inflateReset'
/usr/i686-linux-gnu/bin/ld: build/deps/linux-i686-default_9/lib/libfreetype.a(ftgzip.o): in function `FT_Stream_OpenGzip':
ftgzip.c:(.text+0x86f): undefined reference to `inflateInit2_'
/usr/i686-linux-gnu/bin/ld: ftgzip.c:(.text+0xa2f): undefined reference to `inflateEnd'
/usr/i686-linux-gnu/bin/ld: build/deps/linux-i686-default_9/lib/libfreetype.a(ftgzip.o): in function `FT_Gzip_Uncompress':
ftgzip.c:(.text+0xb81): undefined reference to `inflateInit2_'
/usr/i686-linux-gnu/bin/ld: ftgzip.c:(.text+0xb98): undefined reference to `inflate'
/usr/i686-linux-gnu/bin/ld: ftgzip.c:(.text+0xba7): undefined reference to `inflateEnd'
/usr/i686-linux-gnu/bin/ld: ftgzip.c:(.text+0xc0e): undefined reference to `inflateEnd'

illwieckz avatar May 13 '23 17:05 illwieckz

When building custom zlib as external_deps, I noticed -lz doesn't work, we need to do -lexternal_deps/<folder>/libz.a, hopefully we actually have a code to find i, but we were not using that code when building the game.

illwieckz avatar May 13 '23 17:05 illwieckz

Some other code was also trying to link against the libraries before they were looked for and then before they were found.

illwieckz avatar May 13 '23 17:05 illwieckz

To summarize:

  • Some lib detection code is moved up before it is used, and some code using them moved down after they are detected.
  • set(LIBS_BASE ${LIBS_BASE} rt) is set (not maCOS, not Windows) if librt is not found (it's expected the system provides it anyway).
  • target_link_libraries(srclibs-nacl-native "${LIBS_BASE}") for the non-nexe game code (needs both libz and librt).
  • target_link_libraries(srclibs-mumblelink "${LIBS_BASE}") for the engine (needs librt).
  • target_link_libraries(srclibs-minizip "${LIBS_BASE}") for the engine (needs libz).

illwieckz avatar May 13 '23 17:05 illwieckz