Discussion:
Should I define _GNU_SOURCE?
Victor Porton
2018-01-22 15:55:50 UTC
Permalink
I am writing a software for Linux/Unix which could benefit from
execvpe() C function.

But this function is defined only when -D_GNU_SOURCE.

Question 1: Should I ALWAYS use -D_GNU_SOURCE for compiler options no
matter what are user options?

Question 2: Should I check existence of execvpe() by checking
#if _GNU_SOURCE
or with AC_CHECK_FUNC(execvpe)?

Question 3: Other advice?
Mathieu Lirzin
2018-01-22 16:42:31 UTC
Permalink
Post by Victor Porton
I am writing a software for Linux/Unix which could benefit from
execvpe() C function.
But this function is defined only when -D_GNU_SOURCE.
Question 1: Should I ALWAYS use -D_GNU_SOURCE for compiler options no
matter what are user options?
Question 2: Should I check existence of execvpe() by checking
#if _GNU_SOURCE
or with AC_CHECK_FUNC(execvpe)?
Question 3: Other advice?
It depends what kind of portability you aim.

* If you don't care about portability just ‘AC_CHECK_FUNC(execvpe)’, and
bail out if not found.

* If you care about portability and you have some courage
‘AC_CHECK_FUNC(execvpe)’ and use ‘AC_LIBOBJ’ to provide a replacement
implementation. If you have extra bravery send a patch to
<bug-***@gnu.org> which is a repository for such replacement.

* If you care about portability but you don't have such courage, just
don't use ‘execvpe’. :-)

HTH
--
Mathieu Lirzin
GPG: F2A3 8D7E EB2B 6640 5761 070D 0ADE E100 9460 4D37
Mathieu Lirzin
2018-01-22 16:48:55 UTC
Permalink
Post by Victor Porton
Question 1: Should I ALWAYS use -D_GNU_SOURCE for compiler options no
matter what are user options?
I forgot to answer this question, which is yes. This directive is just
a way to be explicit about the use of GNU extensions during the
compilation phase.
--
Mathieu Lirzin
GPG: F2A3 8D7E EB2B 6640 5761 070D 0ADE E100 9460 4D37
Eric Blake
2018-01-22 16:58:07 UTC
Permalink
Post by Victor Porton
I am writing a software for Linux/Unix which could benefit from
execvpe() C function.
But this function is defined only when -D_GNU_SOURCE.
Question 1: Should I ALWAYS use -D_GNU_SOURCE for compiler options no
matter what are user options?
If you want to enable the use of a platform's extensions, the easiest
way is to use the AC_USE_SYSTEM_EXTENSIONS macro (rather than
-D_GNU_SOURCE, as that only works for a subset of systems), prior to the
rest of your configure.ac that probes which extensions are now available.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
Mathieu Lirzin
2018-01-22 17:19:28 UTC
Permalink
Post by Eric Blake
Post by Victor Porton
I am writing a software for Linux/Unix which could benefit from
execvpe() C function.
But this function is defined only when -D_GNU_SOURCE.
Question 1: Should I ALWAYS use -D_GNU_SOURCE for compiler options no
matter what are user options?
If you want to enable the use of a platform's extensions, the easiest
way is to use the AC_USE_SYSTEM_EXTENSIONS macro (rather than
-D_GNU_SOURCE, as only works for a subset of systems), prior to the
rest of your configure.ac that probes which extensions are now available.
Do you have an example of something failing to compile with
-D_GNU_SOURCE? I trust your claim but I am just curious. :-)

Maybe the Autoconf manual should describe such possible issue in the
"Posix Variants" part?
--
Mathieu Lirzin
GPG: F2A3 8D7E EB2B 6640 5761 070D 0ADE E100 9460 4D37
Paul Eggert
2018-01-22 18:58:49 UTC
Permalink
Post by Mathieu Lirzin
Do you have an example of something failing to compile with
-D_GNU_SOURCE?
He wasn't saying -D_GNU_SOURCE would cause compiles to fail, only that
-D_GNU_SOURCE would not enable extensions on non-GNU platforms. For what
it's worth, some non-Linux kernels have execvpe or equivalent (though I
don't know whether you want to use them....).

Loading...