Ich versuche CMake zu verwenden, um zu finden, ob eine externe Bibliothek von einer anderen Bibliothek abhängt.Mit CMake zum Suchen von Symbolen in Bibliotheken
Beispiel: die HDF5 Bibliothek kann optional mit zlib In Linux verknüpft werden, kann dies mit
readelf -Ws /usr/local/lib/libhdf5.so | grep inflateEnd
54: 0000000000000000 0 FUNC GLOBAL DEFAULT UND inflateEnd
Mit CMake finden es scheint, kann dies mit CheckLibraryExists
https://cmake.org/cmake/help/v3.0/module/CheckLibraryExists.html
finden In Cmake-Skript
set(CMAKE_REQUIRED_LIBRARIES ${HDF5_LIBRARY})
check_library_exists(${HDF5_LIBRARY} inflateEnd "" NEED_ZLIB)
message(${NEED_ZLIB})
if (NEED_ZLIB)
message("-- ZLIB library is needed...")
else()
message("-- ZLIB library is not needed...")
endif()
Ausgang nicht
-- Looking for inflateEnd in /usr/local/lib/libhdf5.so - not found
-- ZLIB library is not needed...
aus diesem Grund fand ich habe die Cmake Version von readelf mit, dass das Symbol würde
aber immer noch gerne wissen, warum findet die oben Cmake Skript :-) versagt
die Arbeitsversion ist
set(have_read_symbols "no")
find_program(read_symbols_prg readelf)
if (${read_symbols_prg} MATCHES "readelf")
set(have_read_symbols "yes")
message("-- Readelf program found: " ${read_symbols_prg})
execute_process(COMMAND ${read_symbols_prg} -Ws ${HDF5_LIBRARY} OUTPUT_FILE ${CMAKE_CURRENT_BINARY_DIR}/symbols.txt)
endif()
if (${have_read_symbols} MATCHES "yes")
message("-- Detecting if HDF5 library ${HDF5_LIBRARY} needs the ZLIB library...")
file(STRINGS ${CMAKE_CURRENT_BINARY_DIR}/symbols.txt NEED_ZLIB REGEX "inflateEnd")
if (NEED_ZLIB)
message("${color_blue}-- ZLIB library is needed...${color_reset}")
else()
message("-- ZLIB library is not needed...")
endif(NEED_ZLIB)
endif()
, die das Symbol
findet-- Detecting if HDF5 library /usr/local/lib/libhdf5.so needs the ZLIB library...
-- ZLIB library is needed...
Sie können 'CMakeError.log' Datei aus Gründen warum' check_library_exists' fehlschlagen. Tatsächlich versucht es, einen Code zu kompilieren und zu verknüpfen, der den Aufruf der Funktion enthält. Ich denke, die Verknüpfung führt zu "Undefined reference", weil hdf5 selbst nicht die Funktion "inflateEnd" definiert, sondern eine in zlib definierte. – Tsyvarev