- 问题
这里可以看到在生成glad.c.o文件的时候出现了"dlclose@GLIBC_2.2.5"无法指向的问题。此时有两个猜测。- ld链接libdl出问题;
- 那么libdl是否存在?
cd /lib/x86_64-linux-gnu find . -iname "*libdl*"
libdl存在。 - glad.c的问题;
- 为了确定是glad.c的问题,将glad.c的位置挪到add_executable较前的位置,发现,build过程提前了。
之前是100%停掉,现在是12%停掉,所以是glad.c出问题。 - libdl是动态库,可以用cmake链接进去,所以在CMake官网搜索可得
target_link_libraries(${PROJECT_NAME} ${CMAKE_DL_LIBS})
- 重新build,成功
- 为了确定是glad.c的问题,将glad.c的位置挪到add_executable较前的位置,发现,build过程提前了。
- ld链接libdl出问题;
- 为什么
cmake_minimum_required(VERSION 3.10)
project(sal_driven_ms)
if (POLICY CMP0072)
set(OpenGL_GL_PREFERENCE LEGACY)
endif()
set(CMAKE_CXX_STANDARD 11)
find_package(OpenGL REQUIRED)
if (OPENGL_FOUND)
include_directories(${OPENGL_INCLUDE_DIRS})
link_libraries(${OPENGL_LIBRARIES})
endif()
find_package(OpenCV REQUIRED)
if (OPENCV_FOUND)
include_directories(${OPENCV_INCLUDE_DIRS})
link_libraries(${OPENCV_LIBRARIES})
endif()
find_package(glfw3 REQUIRED)
include_directories(include)
include_directories(src)
add_executable(sal_driven_ms main.cpp
src/glad.c
src/camera.cpp
src/header.cpp
src/my_utils.cpp
src/renderer.cpp
src/simp_qslim.cpp
)
target_link_libraries(${PROJECT_NAME} glfw)
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})
target_link_libraries(${PROJECT_NAME} ${CMAKE_DL_LIBS})
这份CMakeLists.txt需要额外添加CMAKE_DL_LIBS?
-
一句废话,因为需要dlopen和dlclose;那么哪儿需要dlopen和dlclose?
因为在glad.c中存在平台识别代码片段,其中就包含#include <dlfcn.h>
,该头文件需要调用到dlopen和dlclose; -
TIPS:
target_link_libraries(${PROJECT_NAME} ${CMAKE_DL_LIBS})
,在我的电脑上,需要;在我同学的电脑上,不需要; -
涉及的资料
- https://blog.csdn.net/wteruiycbqqvwt/article/details/103584438
- https://cmake.org/cmake/help/latest/variable/CMAKE_DL_LIBS.html#:~:text=cmake_dl_libs Name of library containing dlopen and dlclose,in it%2C usually -ldl on most UNIX machines.
- https://www.jianshu.com/p/c92e8b81ad04
- 我参考上overstack上关于dlclose+CMake的一个回答,但链接没找到。