Symbol lookup in CMake fails although symbol is pr

2019-07-05 05:32发布

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条回答
做个烂人
2楼-- · 2019-07-05 06:17

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)
查看更多
登录 后发表回答