Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile error with OpenBSD and clang 19 #3252

Open
rhelmot opened this issue Feb 12, 2025 · 3 comments
Open

Compile error with OpenBSD and clang 19 #3252

rhelmot opened this issue Feb 12, 2025 · 3 comments
Labels

Comments

@rhelmot
Copy link

rhelmot commented Feb 12, 2025

Describe the bug
jq will not compile for OpenBSD under clang 19 due to -Werror=implicit-function-declaration being automatic.

Sample errors:

   > src/builtin.c:247:31: error: call to undeclared function 'lgamma_r'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]                                                               
   >   247 |   jv ret = JV_ARRAY(jv_number(lgamma_r(jv_number_value(input), &sign)));                                                                                                                                                     
   >       |                               ^                                                                                                                                                                                              
   > src/builtin.c:1341:10: error: call to undeclared function 'timegm'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]                                                                
   >  1341 |   return timegm(tm);                                                                                                                                                                                                         
   >       |          ^ 

To Reproduce
./configure && make

Expected behavior
A clear and concise description of what you expected to happen.

Environment (please complete the following information):
OpenBSD 7.5, clang 19

Additional context
Fixed with CFLAGS=-D_BSD_SOURCE=1. Autoconf detects these symbols in -lm but they are not visible in headers by default.

@itchyny
Copy link
Contributor

itchyny commented Feb 13, 2025

This patch works?

diff --git a/src/builtin.c b/src/builtin.c
index c0aba96..146c4d0 100644
--- a/src/builtin.c
+++ b/src/builtin.c
@@ -5,6 +5,10 @@
 # define _XPG6
 # define __EXTENSIONS__
 #endif
+#ifdef __GLIBC__
+# define _BSD_SOURCE
+# define _DEFAULT_SOURCE
+#endif
 #include <sys/time.h>
 #include <stdlib.h>
 #include <stddef.h>

@emanuele6
Copy link
Member

emanuele6 commented Feb 13, 2025

I thought this line from configure.ac was supposed to automatically define _BSD_SOURCE on OpenBSD:

AC_USE_SYSTEM_EXTENSIONS


Hmm, no apparently it only sets _OPENBSD_SOURCE ("Enable OpenBSD compatibility extensions on NetBSD. Oddly enough, this does nothing on OpenBSD."), and only on NetBSD; it never sets _BSD_SOURCE:
https://www.gnu.org/software/autoconf/manual/autoconf-2.72/html_node/C-and-Posix-Variants.html

It also depends on the version of autoconf; in 2.65, it doesn't even set _OPENBSD_SOURCE:
https://www.gnu.org/software/autoconf/manual/autoconf-2.65/html_node/Posix-Variants.html

You can only rely on this macro to set _GNU_SOURCE/_POSIX_SOURCE, but not _BSD_SOURCE.

@itchyny
Copy link
Contributor

itchyny commented Feb 13, 2025

Add to CFLAGS?

diff --git a/Makefile.am b/Makefile.am
index c7504e4..cb09065 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -20,7 +20,7 @@ LIBJQ_SRC = src/builtin.c src/bytecode.c src/compile.c src/execute.c    \
 ### C build options
 
 AM_CFLAGS = -Wextra -Wall -Wno-unused-parameter -Wno-unused-function \
-            -Woverlength-strings
+            -Woverlength-strings -D_BSD_SOURCE -D_DEFAULT_SOURCE
 
 if WIN32
 AM_CFLAGS += -municode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants