undefined reference to symbol ‘dlclose@@GLIBC_2.2.5‘

cmake编译时遇到如下报错

/usr/bin/ld: /usr/local/lib/libglfw3.a(posix_module.c.o): undefined reference to symbol 'dlclose@@GLIBC_2.2.5'
/usr/bin/ld: /lib/x86_64-linux-gnu/libdl.so.2: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

在CMakeLists.txt的target_link中添加${CMAKE_DL_LIBS}并不起作用。

target_link_libraries( MyProject ${CMAKE_DL_LIBS})

后来试了一种方法,参考链接
不需要修改CMakeLists.txt, 只需要在cmake命令后面加上-DCMAKE_CXX_STANDARD_LIBRARIES=“-lX11 -ldl”
比如

mkdir build
cd build
cmake .. -DCMAKE_CXX_STANDARD_LIBRARIES="-lX11 -ldl"

解决

你可能感兴趣的:(环境,人工智能)