Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 947100 - sys-devel/bc-1.07.1-r6: fails to compile with musl /gcc15 - getopt.c:1135:1: error: conflicting types for 'getopt'; have 'int(int, char * const*, const char *)'
Summary: sys-devel/bc-1.07.1-r6: fails to compile with musl /gcc15 - getopt.c:1135:1: ...
Status: CONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords: PATCH
Depends on:
Blocks: c23-porting
  Show dependency tree
 
Reported: 2024-12-28 09:14 UTC by meartzheast877
Modified: 2025-05-09 19:23 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
Build log (build.log,7.18 KB, text/plain)
2024-12-28 09:15 UTC, meartzheast877
Details
emerge --info (info.log,5.93 KB, text/plain)
2024-12-28 09:16 UTC, meartzheast877
Details
Patch to fix build on musl (musl.patch,1.71 KB, patch)
2025-05-09 17:30 UTC, Holger Hoffstätte
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description meartzheast877 2024-12-28 09:14:14 UTC
sys-devel/bc crash if you try to compile it using musl and GCC 15. It seems to be the same error of getopt()

Reproducible: Always

Steps to Reproduce:
1. Have a musl system
2. Install GCC 15
3. Try to compile sys-devel/bc
Actual Results:  
The program cannot be compiled

Expected Results:  
It should have compiled and installed successfully.
Comment 1 meartzheast877 2024-12-28 09:15:09 UTC
Created attachment 915345 [details]
Build log
Comment 2 meartzheast877 2024-12-28 09:16:43 UTC
Created attachment 915346 [details]
emerge --info
Comment 3 meartzheast877 2024-12-28 12:33:15 UTC
(In reply to meartzheast877 from comment #0)
> sys-devel/bc doesn't compile using musl and GCC 15. It seems to be the same error of getopt()
> 
> Reproducible: Always
> 
> Steps to Reproduce:
> 1. Have a musl system
> 2. Install GCC 15
> 3. Try to compile sys-devel/bc
> Actual Results:  
> The program cannot be compiled
> 
> Expected Results:  
> It should have compiled and installed successfully.
Comment 4 immolo 2024-12-28 19:31:30 UTC
x86_64-pc-linux-musl-gcc -DHAVE_CONFIG_H  -I. -I..  -I. -I.. -I./../h -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -O2 -pipe -Wall -funsigned-char -O2 -pipe -Wall -funsigned-char -c -o number.o number.c
getopt.c: In function '_getopt_initialize':
getopt.c:348:21: error: too many arguments to function 'getenv'; expected 0, have 1
  348 |   posixly_correct = getenv ("POSIXLY_CORRECT");
      |                     ^~~~~~  ~~~~~~~~~~~~~~~~~
getopt.c:200:14: note: declared here
  200 | extern char *getenv ();
      |              ^~~~~~
getopt.c: At top level:
getopt.c:1135:1: error: conflicting types for 'getopt'; have 'int(int,  char * const*, const char *)'
 1135 | getopt (int argc, char *const *argv, const char *optstring)
      | ^~~~~~
In file included from getopt.c:106:
./../h/getopt.h:144:12: note: previous declaration of 'getopt' with type 'int(void)'
  144 | extern int getopt ();
      |            ^~~~~~
make[2]: *** [Makefile:319: getopt.o] Error 1
Comment 5 zyxhere 2025-05-09 16:56:25 UTC
Temporary fix is to add -std=c99 and -Wno-implicit-function-declaration to CFLAGS
Comment 6 Holger Hoffstätte 2025-05-09 17:26:41 UTC
Problem exists in all versions currently in the tree.
Comment 7 Holger Hoffstätte 2025-05-09 17:30:56 UTC
Created attachment 928222 [details, diff]
Patch to fix build on musl

Patch that fixes compilation on musl; works with all versions.
Also fixes some old-style prototypes.
Tested by dropping into /etc/portage/patches/sys-devel/bc/
Comment 8 Holger Hoffstätte 2025-05-09 17:39:30 UTC
Note that I opted for the least intrusive changes to retrofit the prototypes so that it builds for the !__GNU_LIBRARY__ case. Another way is to unify the whole thing as done in e.g. https://github.com/gentoo/gentoo/pull/40514 but the result is really the same.
Comment 9 zyxhere 2025-05-09 17:55:34 UTC
(In reply to Holger Hoffstätte from comment #7)
> Created attachment 928222 [details, diff] [details, diff]
> Patch to fix build on musl
> 
> Patch that fixes compilation on musl; works with all versions.
> Also fixes some old-style prototypes.
> Tested by dropping into /etc/portage/patches/sys-devel/bc/

I also dropped it in /etc/portage/patches but portage doesn't use it for some reason
Completely ignores it
Comment 10 Holger Hoffstätte 2025-05-09 18:00:17 UTC
$ll /etc/portage/patches/sys-devel/bc/musl.patch 
-rw-r--r-- 1 root root 1.8K May  9 19:21 /etc/portage/patches/sys-devel/bc/musl.patch
$ebuild /var/db/repos/gentoo/sys-devel/bc/bc-1.08.1.ebuild prepare
 * bc-1.08.1.tar.gz BLAKE2B SHA512 size ;-) ...                                      [ ok ]
>>> Unpacking source...
>>> Unpacking bc-1.08.1.tar.gz to /var/tmp/portage/sys-devel/bc-1.08.1/work
>>> Source unpacked in /var/tmp/portage/sys-devel/bc-1.08.1/work
>>> Preparing source in /var/tmp/portage/sys-devel/bc-1.08.1/work/bc-1.08.1 ...
 * ========================================================================================
 * Applying user patches from /etc/portage/patches ...
 * Applying musl.patch ...                                                           [ ok ]
 * User patches applied.
 * ========================================================================================
>>> Source prepared.
Comment 11 zyxhere 2025-05-09 18:02:36 UTC
False alarm it was a permission issue the patch works fine thanks
Comment 12 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2025-05-09 19:23:44 UTC
(In reply to zyxhere from comment #5)
> Temporary fix is to add -std=c99 and -Wno-implicit-function-declaration to
> CFLAGS

FTR, simply -std=gnu17 should be enough. No need for -Wno* (it's a C23 issue). If you *did* need -Wno*, it was probably because of using -std=c instead of -std=gnu.