diff --git a/lib/hostip4.c b/lib/hostip4.c
index 902f022630febbb1a00ca3fb1af0d2f31058ebe8..3e5a12d2be7b9b7e4139d4365e39cf54e33c0628 100644
--- a/lib/hostip4.c
+++ b/lib/hostip4.c
@@ -136,7 +136,7 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
 Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname,
                                    int port)
 {
-#if defined(HAVE_GETHOSTBYNAME_R_3)
+#if !defined(HAVE_GETADDRINFO_THREADSAFE) && defined(HAVE_GETHOSTBYNAME_R_3)
   int res;
 #endif
   Curl_addrinfo *ai = NULL;