首页 > 其他分享 >简单分析"undefined reference to symbol 'dlclose@@GLIBC_2.2.5'"问题的形成和解决

简单分析"undefined reference to symbol 'dlclose@@GLIBC_2.2.5'"问题的形成和解决

时间:2022-10-31 17:23:06浏览次数:83  
标签:src include undefined reference symbol libraries link dlclose glad

  1. 问题
    image
    这里可以看到在生成glad.c.o文件的时候出现了"dlclose@GLIBC_2.2.5"无法指向的问题。此时有两个猜测。
    1. ld链接libdl出问题;
      1. 那么libdl是否存在?
      cd /lib/x86_64-linux-gnu
      find . -iname "*libdl*"
      
      image
      libdl存在。
    2. glad.c的问题;
      1. 为了确定是glad.c的问题,将glad.c的位置挪到add_executable较前的位置,发现,build过程提前了。
        image
        之前是100%停掉,现在是12%停掉,所以是glad.c出问题。
      2. libdl是动态库,可以用cmake链接进去,所以在CMake官网搜索可得
      target_link_libraries(${PROJECT_NAME} ${CMAKE_DL_LIBS})
      
      1. 重新build,成功
        image
  2. 为什么
	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?

  1. 一句废话,因为需要dlopen和dlclose;那么哪儿需要dlopen和dlclose?
    因为在glad.c中存在平台识别代码片段,其中就包含#include <dlfcn.h>,该头文件需要调用到dlopen和dlclose;

  2. TIPS:target_link_libraries(${PROJECT_NAME} ${CMAKE_DL_LIBS}),在我的电脑上,需要;在我同学的电脑上,不需要;

  3. 涉及的资料

    1. https://blog.csdn.net/wteruiycbqqvwt/article/details/103584438
    2. 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.
    3. https://www.jianshu.com/p/c92e8b81ad04
    4. 我参考上overstack上关于dlclose+CMake的一个回答,但链接没找到。

标签:src,include,undefined,reference,symbol,libraries,link,dlclose,glad
From: https://www.cnblogs.com/bkct-tech-blog/p/16844862.html

相关文章