From 6e92a4fa48e2507bd038698e275e72e304c7b594 Mon Sep 17 00:00:00 2001 From: wb2osz Date: Mon, 25 Nov 2019 22:14:46 -0500 Subject: [PATCH] Fix build for CentOS. --- CMakeLists.txt | 12 ++++++++++-- src/ptt.c | 5 ----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 75484c9..a55c351 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -150,8 +150,16 @@ elseif (WIN32) endif() if (C_CLANG OR C_GCC) - # _BSD_SOURCE is deprecated we need to use _DEFAULT_SOURCE - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wvla -ffast-math -ftree-vectorize -D_XOPEN_SOURCE=600 -D_DEFAULT_SOURCE ${EXTRA_FLAGS}") + # _BSD_SOURCE is deprecated we need to use _DEFAULT_SOURCE. + # That might be the case for a more modern compiler but it is still needed + # for CentOS 6 & 7. Without -D_BSD_SOURCE, we get Warning: Implicit declaration of + # functions alloca, cfmakeraw, scandir, setlinebuf, strcasecmp, strncasecmp, and strsep. + # When a function (like strsep) returns a pointer, the compiler instead assumes a 32 bit + # int and sign extends it out to be a 64 bit pointer. Use the pointer and Kaboom! + # + ### Wextra spews out so much noise a serious problem was not noticed. + ###set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wvla -ffast-math -ftree-vectorize -D_XOPEN_SOURCE=600 -D_DEFAULT_SOURCE ${EXTRA_FLAGS}") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wvla -ffast-math -ftree-vectorize -D_XOPEN_SOURCE=600 -D_DEFAULT_SOURCE -D_BSD_SOURCE ${EXTRA_FLAGS}") # for math.h link_libraries("-lm") elseif (C_MSVC) diff --git a/src/ptt.c b/src/ptt.c index 5cc3392..cf49bba 100644 --- a/src/ptt.c +++ b/src/ptt.c @@ -156,11 +156,6 @@ #include #include #include - -#ifndef __USE_BSD -#define __USE_BSD // Needed for gcc 4.8.5 to find definitions for scandir - // and alphasort. Newer compilers don't have this issue. -#endif #include #ifdef USE_HAMLIB