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

Can not compile on FreeBSD 13 #984

Closed
juanmitaboada opened this issue Sep 29, 2021 · 3 comments
Closed

Can not compile on FreeBSD 13 #984

juanmitaboada opened this issue Sep 29, 2021 · 3 comments

Comments

@juanmitaboada
Copy link

After a fresh clone from the repo and trying with gmake, I get the next error:

$ gmake
cc -std=c99 -pedantic -c -O3 -fPIC  -I/usr/local/opt/openssl/include -Wall -W -Wstrict-prototypes -Wwrite-strings -Wno-missing-field-initializers -g -ggdb alloc.c
cc -std=c99 -pedantic -c -O3 -fPIC  -I/usr/local/opt/openssl/include -Wall -W -Wstrict-prototypes -Wwrite-strings -Wno-missing-field-initializers -g -ggdb net.c
cc -std=c99 -pedantic -c -O3 -fPIC  -I/usr/local/opt/openssl/include -Wall -W -Wstrict-prototypes -Wwrite-strings -Wno-missing-field-initializers -g -ggdb hiredis.c
cc -std=c99 -pedantic -c -O3 -fPIC  -I/usr/local/opt/openssl/include -Wall -W -Wstrict-prototypes -Wwrite-strings -Wno-missing-field-initializers -g -ggdb sds.c
cc -std=c99 -pedantic -c -O3 -fPIC  -I/usr/local/opt/openssl/include -Wall -W -Wstrict-prototypes -Wwrite-strings -Wno-missing-field-initializers -g -ggdb async.c
cc -std=c99 -pedantic -c -O3 -fPIC  -I/usr/local/opt/openssl/include -Wall -W -Wstrict-prototypes -Wwrite-strings -Wno-missing-field-initializers -g -ggdb read.c
read.c:312:61: warning: '_Generic' is a C11 extension [-Wc11-extensions]
                if (buf[0] == '\0' || eptr != &buf[len] || !isfinite(d)) {
                                                            ^
/usr/include/math.h:111:21: note: expanded from macro 'isfinite'
#define isfinite(x) __fp_type_select(x, __isfinitef, __isfinite, __isfinitel)
                    ^
/usr/include/math.h:82:39: note: expanded from macro '__fp_type_select'
#define __fp_type_select(x, f, d, ld) _Generic((x),                     \
                                      ^
1 warning generated.
cc -std=c99 -pedantic -c -O3 -fPIC  -I/usr/local/opt/openssl/include -Wall -W -Wstrict-prototypes -Wwrite-strings -Wno-missing-field-initializers -g -ggdb sockcompat.c
cc -shared -Wl,-soname,libhiredis.so.1.0.1-dev -o libhiredis.so alloc.o net.o hiredis.o sds.o async.o read.o sockcompat.o 
ar rcs libhiredis.a alloc.o net.o hiredis.o sds.o async.o read.o sockcompat.o
cc -std=c99 -pedantic -c -O3 -fPIC  -I/usr/local/opt/openssl/include -Wall -W -Wstrict-prototypes -Wwrite-strings -Wno-missing-field-initializers -g -ggdb test.c
test.c:615:15: warning: '_Generic' is a C11 extension [-Wc11-extensions]
              isinf(((redisReply*)reply)->dval) &&
              ^
/usr/include/math.h:112:18: note: expanded from macro 'isinf'
#define isinf(x) __fp_type_select(x, __isinff, __isinf, __isinfl)
                 ^
/usr/include/math.h:82:39: note: expanded from macro '__fp_type_select'
#define __fp_type_select(x, f, d, ld) _Generic((x),                     \
                                      ^
1 warning generated.
cc -o hiredis-test -O3 -fPIC  -I/usr/local/opt/openssl/include -Wall -W -Wstrict-prototypes -Wwrite-strings -Wno-missing-field-initializers -g -ggdb -I. test.o libhiredis.a  
ld: error: undefined symbol: __isfinite
>>> referenced by read.c:312
>>>               read.o:(redisReaderGetReply) in archive libhiredis.a
cc: error: linker command failed with exit code 1 (use -v to see invocation)
gmake: *** [Makefile:211: hiredis-test] Error 1
@michael-grunder
Copy link
Collaborator

I only scanned the linked topics, but this appears to be a problem upstream in FreeBSD's math.h header.

TL;DR: We're compiling with -std=c99 but for some reason, the C11 _Generic feature is being invoked. You can attempt to compile without -pedantic although the error we get is slightly different than the others I link below.

See:
igraph/igraph#1748
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=254714

@ac000
Copy link

ac000 commented Dec 8, 2021

@juanmitaboada The following patch will make it build on FreeBSD (below is tested on 13.0)

diff --git a/Makefile b/Makefile
index f30c2ac..87c79e1 100644
--- a/Makefile
+++ b/Makefile
@@ -92,6 +92,10 @@ else
   SSL_LDFLAGS+=-L$(OPENSSL_PREFIX)/lib -lssl -lcrypto
 endif
 
+ifeq ($(uname_S),FreeBSD)
+  LDFLAGS+=-lm
+endif
+
 ifeq ($(uname_S),SunOS)
   IS_SUN_CC=$(shell sh -c '$(CC) -V 2>&1 |egrep -i -c "sun|studio"')
   ifeq ($(IS_SUN_CC),1)
@@ -231,7 +235,7 @@ check: hiredis-test
        TEST_SSL=$(USE_SSL) ./test.sh
 
 .c.o:
-       $(CC) -std=c99 -pedantic -c $(REAL_CFLAGS) $<
+       $(CC) -std=c99 -c $(REAL_CFLAGS) $<
 
 clean:
        rm -rf $(DYLIBNAME) $(STLIBNAME) $(SSL_DYLIBNAME) $(SSL_STLIBNAME) $(TESTS) $(PKGCONFNAME) examples/hiredis-example* *.o *.gcda *.gcno *.gcov

Or you can leave -pedantic in and compile with GCC I.e gmake CC=gcc

michael-grunder added a commit that referenced this issue Dec 9, 2021
michael-grunder added a commit that referenced this issue Dec 10, 2021
@michael-grunder
Copy link
Collaborator

michael-grunder commented Dec 10, 2021

See #1026

@ac000 I tweaked your changes a little bit to keep -pedantic in FreeBSD if the compiler is GCC. Probably not a big deal either way but if possible I'd prefer not to pessimize the build.

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

No branches or pull requests

3 participants