Bug 487995

Summary: basename prototype mis-match between libiberty.h and string.h
Product: [Fedora] Fedora Reporter: William Cohen <wcohen>
Component: binutilsAssignee: Nick Clifton <nickc>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: low    
Version: rawhideCC: jakub, jan.kratochvil, nickc
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2009-04-09 14:45:35 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
short program prototype mismatch none

Description William Cohen 2009-03-02 04:32:29 UTC
Created attachment 333680 [details]
short program prototype mismatch

Description of problem:

The declaration in /usr/include/libiberty.h from binutils-devel rpm for basename does not match the current declaration in /usr/include/string.h. When compiling oprofile got the following error:

g++ -DHAVE_CONFIG_H -I. -I..  -I ../libutil -I ../libop -I ../libpp  -W -Wall -fno-common -ftemplate-depth-50 -g -MT child_reader.o -MD -MP -MF .deps/child_reader.Tpo -c -o child_reader.o child_reader.cpp
In file included from ../libutil/op_libiberty.h:27,
                 from child_reader.cpp:22:
/usr/include/libiberty.h:105: error: new declaration ‘char* basename(const char*)’
/usr/include/string.h:599: error: ambiguates old declaration ‘const char* basename(const char*)’
make[3]: *** [child_reader.o] Error 1
make[3]: Leaving directory `/home/wcohen/rh-rpms/BUILD/oprofile-0.9.4/libutil++'
make[2]: *** [all-recursive] Error 1

Can see this problem in:
http://koji.fedoraproject.org/koji/taskinfo?taskID=1186823

Version-Release number of selected component (if applicable):
binutils-devel-2.19.51.0.2-14.fc11.i586
glibc-headers-2.9.90-8.1.i586

How reproducible:

Every time. Can reproduce with simple program.

Attempt to build 


Steps to Reproduce:
1. have the needed rpms installed on machine
2. g++ -c b.cpp
  
Actual results:

Get the following error:

 g++ -c /tmp/b.cpp
In file included from /tmp/b.cpp:2:
/usr/include/libiberty.h:105: error: new declaration ‘char* basename(const char*)’
/usr/include/string.h:599: error: ambiguates old declaration ‘const char* basename(const char*)’
/tmp/b.cpp: In function ‘int main(int, char**)’:
/tmp/b.cpp:9: error: invalid conversion from ‘const char*’ to ‘char’



Expected results:

Compile without error.


Additional info:

Comment 1 Nick Clifton 2009-03-06 11:21:24 UTC
Hi Will,

  First of all there is a small mistake in your example program (b.cpp).  Currently you are assigning the result of calling basename() into a char, hence the error message for line 9 in b.cpp.  Also the pointer returned by basename, according to string.h, is a const char *, so you have a type mismatch as well.  Hence I changed the source to:

  [...]
  const char *b;
  int main(int argc, char **argv)
  {
    b = basename("/usr/bin/xyz.sdf");
  [...]

Which just leaves the ambiguity between libiberty.h and string.h.  I do not really think that libiberty.h is at fault here, since it is following the XPG specifications for the basename function.  (Rather than the ISO C++ specification which is what is being used by string.h).  An easy workaround is to define HAVE_DECL_BASENAME to 1 before including libiberty.h, like this:

  #include <string.h>
  #define HAVE_DECL_BASENAME 1
  #include <libiberty.h>

Or use autoconf to test for basename and include config.h before libiberty.h.

Cheers
  Nick

Comment 2 William Cohen 2009-04-08 19:42:02 UTC
Added the following in the configure.in:

AC_CHECK_DECLS([basename], [], [], [[#include <libgen.h>]])

This produces the needed define in config.h and allows things to compile on f11.

Comment 3 William Cohen 2009-04-09 14:45:35 UTC
Have fix in oprofile-0.9.4-6.fc11.