StuS
May 19, 2023, 2:35pm
#1
After setting up the automated testing framework and checking that it works correctly by running the stubs (code found under ex30.c), I include the actual test (code found under libex29_tests.c) and I keep getting this error everytime I run ‘make all’ or ‘make tests’ once the build has completed:
It appears that the
#include <dlfcn.h> directive is not picking up this header file, resulting in the undefined reference problem.
Has anyone experienced this before?
I am using Ubuntu 20.04.1 and gcc 9.4.0
StuS
May 19, 2023, 2:45pm
#2
Update:
iIt seems this is a known issue with GCC on linux:
opened 09:21PM - 22 Feb 21 UTC
closed 01:31AM - 14 Jun 22 UTC
infrastructure
Using GCC-10 on Linux fails with an undefined reference to `dlsym`. The Cmake co… nfiguration
`cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_BUILD_TYPE=Debug`
Based on whats described here
https://github.com/Intel-Media-SDK/MediaSDK/issues/34
The fix was to add `-Wl,--no-as-needed -ldl`
This change to CMakeLists.txt at the root directory seemed to get past it
```
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 243e3e618..fc9554248 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -233,11 +233,13 @@ set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
iree_append_list_to_string(CMAKE_C_FLAGS_DEBUG ${IREE_C_FLAGS_DEBUG_LIST})
iree_append_list_to_string(CMAKE_CXX_FLAGS_DEBUG ${IREE_CXX_FLAGS_DEBUG_LIST})
+set(CMAKE_EXE_LINKER_FLAGS "-Wl,--no-as-needed -ldl")
set(CMAKE_CXX_FLAGS_FASTBUILD "-gmlt" CACHE STRING "Flags used by the C++ compiler during fast builds." FORCE)
set(CMAKE_C_FLAGS_FASTBUILD "-gmlt" CACHE STRING "Flags used by the C compiler during fast builds." FORCE)
set(CMAKE_EXE_LINKER_FLAGS_FASTBUILD "-Wl,-S" CACHE STRING "Flags used for linking binaries during fast builds." FORCE)
set(CMAKE_SHARED_LINKER_FLAGS_FASTBUILD "-Wl,-S" CACHE STRING "Flags used by the shared libraries linker binaries during fast builds." FORCE)
mark_as_advanced(
+ CMAKE_EXE_LINKER_FLAGS
CMAKE_CXX_FLAGS_FASTBUILD
CMAKE_C_FLAGS_FASTBUILD
CMAKE_EXE_LINKER_FLAGS_FASTBUILD
```
The solution is to add “-Wl,–no-as-needed -ldl” to the CFLAGS for tests in the Makefile.
This works.