树莓派安装restbed库时出现dlopen/dlclose未定义引用错误
dlopen Undefined Reference Error When Installing Restbed on Raspberry Pi What's Causing the Error?
The error points to an undefined reference to dlopen in OpenSSL's static libcrypto.a library. When statically linking OpenSSL on Raspbian, you need to explicitly link against the dynamic loading library (libdl), which provides functions like dlopen. Restbed's test suite configuration doesn't include this dependency by default for the Raspberry Pi, hence the linking failure.
Solution 1: Skip the Test Suite (Quickest Fix)
If you don't need to run Restbed's unit tests (the core library will still install and work perfectly), you can disable test compilation entirely:
- Navigate to your restbed
builddirectory and clean up previous build artifacts:make clean rm -rf CMakeCache.txt CMakeFiles/ - Re-run CMake with the test build disabled:
cmake .. -DBUILD_TESTS=OFF - Compile and install the library as usual:
make sudo make install
Solution 2: Fix the Test Suite Linking (If You Want to Run Tests)
If you want to validate the installation with the unit tests, you need to add the libdl dependency to the test target:
- Open the test CMake configuration file in the Restbed source directory—this is typically at
restbed/test/CMakeLists.txt. - Locate the line where the test executable is defined, which looks like:
add_executable(service_unit_test_suite ${TEST_SOURCES}) - Add a line immediately after it to link against libdl:
target_link_libraries(service_unit_test_suite PRIVATE dl) - Return to your
builddirectory, re-run CMake, then compile and install:cmake .. make sudo make install
Alternative: Add Linker Flags Directly in CMake
You can also pass the required linker flag to CMake without modifying any source files:
cmake .. -DCMAKE_EXE_LINKER_FLAGS="-ldl" make sudo make install
This ensures all executable targets (including the test suite) link against libdl, resolving the undefined reference error right away.
内容的提问来源于stack exchange,提问作者RomanR

