undefined reference to `__res_query’

Question:

Trying to link Chilkat (C++) with the following libs:

LIBS=-lstdc++fs \
-pthread \
-L${FMT_LIB} -lfmt \
-lspdlog \
/usr/local/lib/libredis++.a \
${BOOST_LIB}/libboost_json.a \
...
...
${CHILKAT_LIB}/libchilkat-9.5.0.a \
-lmongoc-1.0 -lbson-1.0 \
-lpthread \
-ldl \
-lresolv

After we went from ubuntu 21 to 22 LTS, using same compiler, it stopped working.

Now we get errors:

/usr/bin/ld: ... libchilkat-9.5.0.a(ChilkatResolve.o): in function `ChilkatResolve::bestMxLookup(char const*, StringBuffer&, LogBase&, bool)':
ChilkatResolve.cpp:(.text+0x2c6): undefined reference to `__res_query'

/usr/bin/ld: ... libchilkat-9.5.0.a(ChilkatResolve.o): in function `ChilkatResolve::dkimLookup(char const*, StringBuffer&, LogBase&, bool)':
ChilkatResolve.cpp:(.text+0x47f): undefined reference to `__res_query'

/usr/bin/ld: ... libchilkat-9.5.0.a(ChilkatResolve.o): in function `ChilkatResolve::mxLookup(char const*, ScoredStrings&, LogBase&, bool)':
ChilkatResolve.cpp:(.text+0x64e): undefined reference to `__res_query'

collect2: error: ld returned 1 exit status
make: *** [Makefile:47: debug] Error 1

When we change to dynamic linking, using -L${CHILKAT_LIB} -lchilkat-9.5.0 instead of ${CHILKAT_LIB}/libchilkat-9.5.0.a  it builds.

res_query is part of the DNS resolver library. See https://linux.die.net/man/3/res_query

The man page for res_query tells you what must be linked, and it is “Link with -lresolv”

I can see you have “-lresolv” in your list of LIBS. However, you’re on a new machine, so it’s probably the case that the -lresolv library is not yet installed on the machine, or somehow it is not found.

Tags :