Bug 43822 - linker can not find res_init() (defined in resolv.h) when compiling
Summary: linker can not find res_init() (defined in resolv.h) when compiling
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: glibc
Version: 7.1
Hardware: i686
OS: Linux
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Aaron Brown
Depends On:
TreeView+ depends on / blocked
Reported: 2001-06-07 11:46 UTC by Scott Sibert
Modified: 2016-11-24 14:58 UTC (History)
1 user (show)

Clone Of:
Last Closed: 2001-06-08 12:41:54 UTC

Attachments (Terms of Use)

Description Scott Sibert 2001-06-07 11:46:47 UTC
From Bugzilla Helper:
User-Agent: Mozilla/4.76 [en] (X11; U; Linux 2.4.2-2smp i686)

Description of problem:
here is a sample program:

char res_init();
int main() {
  return 0;

This gives the following results (sample program is ch.c compiling to

[sibertsa@dopey w1]$ cc -o conftest -Wall
/tmp/ccszaKJC.o: In function `main':
/tmp/ccszaKJC.o(.text+0x7): undefined reference to `res_init'
collect2: ld returned 1 exit status
[sibertsa@dopey w1]$ 

This works on RedHat 7.0 i686

How reproducible:

Steps to Reproduce:
1.  See Description

Actual Results:  See Description

Expected Results:  expected sample program to compile successfully

Additional info:

This is straight RedHat 7.1 without any updates on a dual P2/300.  The RH70
machine is a dual P3/800 and has most but recent updates (just haven't
looked lately).  I've looked through the errata for RH71 and don't see
anything that would relate to this problem.

Comment 1 Jakub Jelinek 2001-06-07 11:54:42 UTC
Your example program is buggy. You should simply never define prototypes provided
by glibc, you should include proper header files instead (in this case
<resolv.h>). That will take care of making it actually __res_init which is
what glibc exports.

Comment 2 Scott Sibert 2001-06-07 13:35:30 UTC
Sample program came from a configure script; here is its reasoning behind
redefining the prototype:

/* Override any gcc2 internal prototype to avoid an error.  */
/* We use char because int might match the return type of a gcc2
    builtin and then its argument prototype would still apply.  */
char res_init();

Interesting thing is that the compile returned no errors on RH70 whereas it did
on RH71.

Comment 3 Jakub Jelinek 2001-06-07 13:49:46 UTC
Then the configure script should be fixed. There really is no res_init in glibc,
only __res_init (and res_init for binaries compiled against glibc 2.0 and
glibc 2.1).

Comment 4 Scott Sibert 2001-06-07 13:57:06 UTC
Before I make changes to the configure script, any idea why this compiles on
RH70 and not on RH71?  The configure script works correctly on RH70 and I need
to make sure I don't mess something up for another platform or RH version.

Comment 5 Scott Sibert 2001-06-08 12:41:50 UTC
The functionality of gcc or glibc (or maybe binutils) has changed.  What changed
to cause one or more to function differently than in RedHat 7.0?  Either "it now
does such-and-such" or "it no longer does such-and-such" but something has
changed functionally.  I see nothing in the Release Notes describing such
functionality change.

Comment 6 Jakub Jelinek 2001-06-10 10:17:45 UTC
res_init was deliberately removed from default symbol versions
in glibc 2.2 to show that it should not be used (programs linked
against it already will keep working, but no new programs can be
linked against it). Glibc since 2.2 uses __res_init instead, programs
which properly include <resolv.h> will compile just fine.
The autoconf test if really needed could be e.g.
test for AC_TRY_LINK_FUNC(res_init,...) and if that fails try

Note You need to log in before you can comment on or make changes to this bug.