* bug#32767: glibc shadows gcc's C++ headers
@ 2018-09-19 0:32 Robin Templeton
2021-03-09 21:35 ` Maxim Cournoyer
0 siblings, 1 reply; 2+ messages in thread
From: Robin Templeton @ 2018-09-19 0:32 UTC (permalink / raw)
To: 32767
When compiling C++ programs, glibc's include directory takes precedence
over gcc's for standard C headers like math.h, but glibc's headers
aren't completely compatible with C++. For example, isnan from math.h is
supposed to be a function, but glibc defines it as a macro.
This program demonstrates the problem:
#include <math.h>
int main(void) { int isnan(0); return isnan; }
It works as expected when gcc's built-in C++ headers are used, but not
if glibc is installed:
% guix environment --pure --ad-hoc gcc -- g++ -E isnan.cpp | tail -n1
int main (void) { int isnan (0); return isnan; }
% guix environment --pure --ad-hoc gcc glibc -- g++ -E isnan.cpp | tail -n1
int main (void) { int __builtin_isnan (0); return isnan; }
As a temporary workaround, I'm using the following package as a
replacement for glibc, to keep the glibc headers out of $CPATH. If it's
installed along with gcc, ld-wrapper and binutils, the test program
compiles without errors.
(use-modules (guix) (gnu))
(use-package-modules base)
(package
(inherit glibc)
(name "my-glibc")
(arguments
(substitute-keyword-arguments (package-arguments glibc)
((#:phases phases)
`(modify-phases ,phases
(add-after 'install 'move-include
(lambda _
(rename-file (string-append %output "/include")
(string-append %output "/include-glibc"))
#t)))))))
^ permalink raw reply [flat|nested] 2+ messages in thread
* bug#32767: glibc shadows gcc's C++ headers
2018-09-19 0:32 bug#32767: glibc shadows gcc's C++ headers Robin Templeton
@ 2021-03-09 21:35 ` Maxim Cournoyer
0 siblings, 0 replies; 2+ messages in thread
From: Maxim Cournoyer @ 2021-03-09 21:35 UTC (permalink / raw)
To: Robin Templeton; +Cc: 32767-done
Hello,
Robin Templeton <robin@igalia.com> writes:
> When compiling C++ programs, glibc's include directory takes precedence
> over gcc's for standard C headers like math.h, but glibc's headers
> aren't completely compatible with C++. For example, isnan from math.h is
> supposed to be a function, but glibc defines it as a macro.
>
> This program demonstrates the problem:
>
> #include <math.h>
> int main(void) { int isnan(0); return isnan; }
>
> It works as expected when gcc's built-in C++ headers are used, but not
> if glibc is installed:
>
> % guix environment --pure --ad-hoc gcc -- g++ -E isnan.cpp | tail -n1
> int main (void) { int isnan (0); return isnan; }
> % guix environment --pure --ad-hoc gcc glibc -- g++ -E isnan.cpp | tail -n1
> int main (void) { int __builtin_isnan (0); return isnan; }
>
> As a temporary workaround, I'm using the following package as a
> replacement for glibc, to keep the glibc headers out of $CPATH. If it's
> installed along with gcc, ld-wrapper and binutils, the test program
> compiles without errors.
>
> (use-modules (guix) (gnu))
> (use-package-modules base)
> (package
> (inherit glibc)
> (name "my-glibc")
> (arguments
> (substitute-keyword-arguments (package-arguments glibc)
> ((#:phases phases)
> `(modify-phases ,phases
> (add-after 'install 'move-include
> (lambda _
> (rename-file (string-append %output "/include")
> (string-append %output "/include-glibc"))
> #t)))))))
Thanks for the report. Nowadays the recommended way to install the
GCC-based toolchain is to use the 'gcc-toolchain' package. The 'gcc'
package is now even made hidden in Guix, which doesn't seem to have this
particular issue:
$ guix environment --pure --ad-hoc gcc-toolchain -- g++ -E /tmp/isnan.cpp | tail -n1
int main(void) { int isnan(0); return isnan; }
$ guix environment --pure --ad-hoc gcc-toolchain glibc -- g++ -E /tmp/isnan.cpp | tail -n1
int main(void) { int isnan(0); return isnan; }
I'm closing this issue, but feel free to open a fresh one if you still
encounter problems.
Thank you,
Maxim
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-03-09 21:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-19 0:32 bug#32767: glibc shadows gcc's C++ headers Robin Templeton
2021-03-09 21:35 ` Maxim Cournoyer
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).