From a533cb246c9e0fa373a65df3e51f9dc0f570f7ac Mon Sep 17 00:00:00 2001 From: Giacomo Travaglini Date: Mon, 19 Dec 2022 16:08:29 +0000 Subject: [PATCH] scons: Include libraries when building gem5 as a shared object While we include shared libraries in the Executable class, we are not doing it when linking the SharedLib. This means the resulting Shared library won't have the library as a dependency (it won't appear in ldd) and the symbols will remain undefined. Any executable will fail to link with the shared library as the executable will contain undefined references. This bug was exposed when I tried to link util/tlm sources with libgem5.so. As I have libpng/libpng-dev installed in my machine, the shared library included libpng headers, but didn't link to the library as scons didn't append "-lpng" to the linking CL. Those png functions thus remained ubdefined symbols. Change-Id: Id9c4a65607a7177f71659f1ac400a67edf7080fd Signed-off-by: Giacomo Travaglini Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/66855 Tested-by: kokoro Reviewed-by: Gabe Black Maintainer: Daniel Carvalho Reviewed-by: Daniel Carvalho Reviewed-by: Bobby Bruce --- src/SConscript | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/SConscript b/src/SConscript index 4e7139c064..51b4bd9b3b 100644 --- a/src/SConscript +++ b/src/SConscript @@ -376,6 +376,12 @@ class SharedLib(TopLevelBase): def declare(self, env): objs = self.srcs_to_objs(env, self.sources(env)) + libs = self.libs(env) + # Higher priority libraries should be earlier in the list. + libs.sort(key=lambda l: l.priority, reverse=True) + if libs: + env.Append(LIBS=list(lib.source for lib in libs)) + date_obj = env.SharedObject(date_source) env.Depends(date_obj, objs)