尽管存在符号,但CMake中的符号查找失败 [英] Symbol lookup in CMake fails although symbol is present
本文介绍了尽管存在符号,但CMake中的符号查找失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用CMake检查符号getaddrinfo_a是否存在:
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)
虽然在netdb.h中定义了getaddrinfo_a(假设已定义_GNU_SOURCE),但CMake找不到它:
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.
知道我在做什么错吗?
推荐答案
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)
这篇关于尽管存在符号,但CMake中的符号查找失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文