undefined reference to `__res_query'

Issues related to applications and software problems and general support
Post Reply
jeffsmith82
Posts: 21
Joined: 2018/11/29 14:29:36

undefined reference to `__res_query'

Post by jeffsmith82 » 2023/02/07 10:33:44

Built a new CentOS 9 machine and i'm trying to compile some C++ code that worked on CentOS 8.

I'm seeing the following and a few other similar ones when trying to link

Code: Select all

/usr/bin/ld: /home/build/builds/_shared/supplier/chilkat/libs/x64/libchilkat.a(ChilkatResolve.o): in function `ChilkatResolve::mxLookup(char const*, ScoredStrings&, LogBase&, bool)':
ChilkatResolve.cpp:(.text+0x64e): undefined reference to `__res_query'
I think its related to the version of glibc being 2.34 which says the following https://lwn.net/Articles/864920/
Various symbols previously defined in libresolv have been moved to libc
in order to prepare for libresolv moving entirely into libc (see earlier
entry for merging libraries into libc). The symbols __dn_comp,
__dn_expand, __dn_skipname, __res_dnok, __res_hnok, __res_mailok,
__res_mkquery, __res_nmkquery, __res_nquery, __res_nquerydomain,
__res_nsearch, __res_nsend, __res_ownok, __res_query, __res_querydomain,
__res_search, __res_send formerly in libresolv have been renamed and no
longer have a __ prefix. They are now available in libc.
Any ideas how I can get this code to compile. Im currently using these flags so -lresolve is there

Code: Select all

-std=c++20 -ldl -lrt -lstdc++fs -lstdc++ -lresolv
and it this version of GCC.

Code: Select all

g++ (GCC) 11.3.1 20221121 (Red Hat 11.3.1-4)

BShT
Posts: 583
Joined: 2019/10/09 12:31:40

Re: undefined reference to `__res_query'

Post by BShT » 2023/02/07 12:03:17

Centos 9 is a beta product, try to compile it under RHEL9, Rocky 9, Oracle 9 or Alma 9 and see

User avatar
jlehtone
Posts: 4523
Joined: 2007/12/11 08:17:33
Location: Finland

Re: undefined reference to `__res_query'

Post by jlehtone » 2023/02/07 12:07:02

First, the symbols are clearly declared in the headers that your compiler does use, because you do get to linker phase.

Furthermore, they seem to be in text section of libc, just like the note that you did find does say:

Code: Select all

[Alma9 ~]$ strings /lib64/libresolv.so.2 | grep res_que
__res_queriesmatch
__libc_res_queriesmatch

[Alma9 ~]$ strings /lib64/libc.so.6 | grep res_que
__libc_res_queriesmatch
__res_querydomain
__res_query
res_query.c
__GI___libc_res_queriesmatch.part.0
___res_querydomain
___res_query
__GI___libc_res_queriesmatch
res_querydomain@@GLIBC_2.34
__res_querydomain@GLIBC_2.2.5
res_query@@GLIBC_2.34
__res_query@GLIBC_2.2.5

[Alma9 ~]$  nm /lib64/libc.so.6 | grep res_query
0000000000172b20 t ___res_query
0000000000173540 t ___res_querydomain
0000000000173540 T __res_querydomain@GLIBC_2.2.5
0000000000173540 T res_querydomain@@GLIBC_2.34
0000000000172b20 T __res_query@GLIBC_2.2.5
0000000000172b20 T res_query@@GLIBC_2.34
One would expect that libc is implicitly included, but perhaps you have to explicitly tell the linker: -lc

jeffsmith82
Posts: 21
Joined: 2018/11/29 14:29:36

Re: undefined reference to `__res_query'

Post by jeffsmith82 » 2023/02/07 12:47:25

This is CentOS stream 9 and the output from the commands you posted from alam is identical as far as I can see.

Code: Select all

 strings /lib64/libresolv.so.2 | grep res_que
__res_queriesmatch
__libc_res_queriesmatch

 strings /lib64/libc.so.6 | grep res_que
__libc_res_queriesmatch
__res_querydomain
__res_query
res_query.c
__GI___libc_res_queriesmatch.part.0
___res_querydomain
___res_query
__GI___libc_res_queriesmatch
res_querydomain@@GLIBC_2.34
__res_querydomain@GLIBC_2.2.5
res_query@@GLIBC_2.34
__res_query@GLIBC_2.2.5

 nm /lib64/libc.so.6 | grep res_query
0000000000172c20 t ___res_query
0000000000173640 t ___res_querydomain
0000000000173640 T __res_querydomain@GLIBC_2.2.5
0000000000173640 T res_querydomain@@GLIBC_2.34
0000000000172c20 T __res_query@GLIBC_2.2.5
0000000000172c20 T res_query@@GLIBC_2.34
Tried adding -lc at the linking stage and still no joy.

User avatar
jlehtone
Posts: 4523
Joined: 2007/12/11 08:17:33
Location: Finland

Re: undefined reference to `__res_query'

Post by jlehtone » 2023/02/07 12:58:47

At some point the linker did want the object-files and libs in specific order (but that might have been last millenia).

I've probably never used underscore-prefixed symbols from libs, so have no idea of their quirks. Are they really part of the interface?

jeffsmith82
Posts: 21
Joined: 2018/11/29 14:29:36

Re: undefined reference to `__res_query'

Post by jeffsmith82 » 2023/02/07 13:04:16

From what I understand if you wrap it in start/end group it doesn't matter which order it gets defined.

Code: Select all

-Wl,--start-group -ldl -lrt -std=c++20 -lc -lstdc++fs -lstdc++ -lresolv -pthread @(OBJS) @(LIBS) -Wl,--end-group
Its a thridparty lib that we dont have source code for that's not linking but used to on gcc 8.5 .

User avatar
TrevorH
Site Admin
Posts: 33191
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: undefined reference to `__res_query'

Post by TrevorH » 2023/02/07 16:16:29

I too would try this on a real clone of RHEL. You never know what is broken this week in Stream so testing on the real thing is worth the effort, just in case. Try Rocky/Alma/OEL or even RHEL itself - you can run up to 16 instances of RHEL using their free developer subscription which you certainly qualify for (everyone does but you'd actually be using it for development!).
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

jeffsmith82
Posts: 21
Joined: 2018/11/29 14:29:36

Re: undefined reference to `__res_query'

Post by jeffsmith82 » 2023/02/13 16:45:15

Installed rocky and getting the same error. :-(

Might just be the third party lib. Is there anywhere else like a gcc IRC would be a good place to ask ?

User avatar
TrevorH
Site Admin
Posts: 33191
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: undefined reference to `__res_query'

Post by TrevorH » 2023/02/13 17:05:40

https://cknotes.com/undefined-reference-to-__res_query/ - that pretty much says what you already quoted. This one is more specific and might be more help https://forums.fedoraforum.org/showthre ... &p=1860899 as I think you have to write a wrapper lib to take __res_query and convert to the thing it uses now.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

jeffsmith82
Posts: 21
Joined: 2018/11/29 14:29:36

Re: undefined reference to `__res_query'

Post by jeffsmith82 » 2023/02/13 22:35:27

That fedora forums posts seems to do the trick many thanks for that. Going to hopefully nudge the maintainer and get him to fix the library.

Post Reply