Symbol lookup in CMake fails although symbol is present

不羁岁月 提交于 2020-01-04 02:56:12

问题


I am trying to check whether symbol getaddrinfo_a exists using CMake:

list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
check_symbol_exists(getaddrinfo_a netdb.h HAVE_GETADDRINFO_A)
list(REMOVE_ITEM CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)

While getaddrinfo_a is defined in netdb.h (given that _GNU_SOURCE is defined), CMake fails to find it:

-- Looking for getaddrinfo_a
-- Looking for getaddrinfo_a - not found.

Any idea what am I doing wrong?


回答1:


According to the getaddrinfo_a man page, the function requires libanl at link time. Try setting CMAKE_REQUIRED_LIBRARIES before invoking check_symbol_exists:

list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
list(APPEND CMAKE_REQUIRED_LIBRARIES anl)
check_symbol_exists(getaddrinfo netdb.h HAVE_GETADDRINFO_A)


来源:https://stackoverflow.com/questions/13541788/symbol-lookup-in-cmake-fails-although-symbol-is-present

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!