From c2b268fd9d27eb59ee604194d354faf6afbf0c96 Mon Sep 17 00:00:00 2001 From: Jiwoo Park Date: Sat, 9 Nov 2024 21:09:12 +0900 Subject: [PATCH] Use `_GNU_SOURCE` macro on Android (#914) I've got the following error while building c-ares on Android. ``` FAILED: _deps/c-ares-source-build/src/lib/CMakeFiles/c-ares.dir/Debug/event/ares_event_wake_pipe.c.o /Users/jimmy.park/Library/Android/sdk/ndk/27.2.12479018/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang --target=armv7-none-linux-androideabi33 --sysroot=/Users/jimmy.park/Library/Android/sdk/ndk/27.2.12479018/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -DCARES_BUILDING_LIBRARY -DHAVE_CONFIG_H=1 -DCMAKE_INTDIR=\"Debug\" -I/Users/jimmy.park/test-c-ares/build/android-arm/_deps/c-ares-source-build -I/Users/jimmy.park/test-c-ares/build/.cache/c-ares-source/b6ff14176cd38f824ca7aa8b1acab422ed5556a6 -I/Users/jimmy.park/test-c-ares/build/.cache/c-ares-source/b6ff14176cd38f824ca7aa8b1acab422ed5556a6/include -I/Users/jimmy.park/test-c-ares/build/.cache/c-ares-source/b6ff14176cd38f824ca7aa8b1acab422ed5556a6/src/lib -I/Users/jimmy.park/test-c-ares/build/.cache/c-ares-source/b6ff14176cd38f824ca7aa8b1acab422ed5556a6/src/lib/include -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security -Wall -Wextra -Waggregate-return -Wcast-align -Wcast-qual -Wconversion -Wdeclaration-after-statement -Wdouble-promotion -Wfloat-equal -Wformat-security -Winit-self -Wmissing-braces -Wmissing-declarations -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-prototypes -Wnested-externs -Wold-style-definition -Wpacked -Wpedantic -Wpointer-arith -Wredundant-decls -Wshadow -Wsign-conversion -Wstrict-overflow -Wstrict-prototypes -Wundef -Wunreachable-code -Wunused -Wvariadic-macros -Wvla -Wwrite-strings -Werror=implicit-int -Werror=implicit-function-declaration -Werror=partial-availability -Qunused-arguments -Wno-long-long -fdiagnostics-color=always -fcolor-diagnostics -fno-limit-debug-info -fno-omit-frame-pointer -O0 -std=c99 -fPIC -fcolor-diagnostics -w -MD -MT _deps/c-ares-source-build/src/lib/CMakeFiles/c-ares.dir/Debug/event/ares_event_wake_pipe.c.o -MF _deps/c-ares-source-build/src/lib/CMakeFiles/c-ares.dir/Debug/event/ares_event_wake_pipe.c.o.d -o _deps/c-ares-source-build/src/lib/CMakeFiles/c-ares.dir/Debug/event/ares_event_wake_pipe.c.o -c /Users/jimmy.park/test-c-ares/build/.cache/c-ares-source/b6ff14176cd38f824ca7aa8b1acab422ed5556a6/src/lib/event/ares_event_wake_pipe.c /Users/jimmy.park/test-c-ares/build/.cache/c-ares-source/b6ff14176cd38f824ca7aa8b1acab422ed5556a6/src/lib/event/ares_event_wake_pipe.c:68:7: error: call to undeclared function 'pipe2'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] 68 | if (pipe2(p->filedes, O_NONBLOCK | O_CLOEXEC) != 0) { | ^ /Users/jimmy.park/test-c-ares/build/.cache/c-ares-source/b6ff14176cd38f824ca7aa8b1acab422ed5556a6/src/lib/event/ares_event_wake_pipe.c:68:7: note: did you mean 'pipe'? /Users/jimmy.park/Library/Android/sdk/ndk/27.2.12479018/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/unistd.h:275:5: note: 'pipe' declared here 275 | int pipe(int __fds[_Nonnull 2]); | ^ 1 error generated. ``` It seems like the `_GNU_SOURCE` macro should be defined because of the [`pipe2` function](https://linux.die.net/man/2/pipe). Authored-By: Jiwoo Park (@jimmy-park) --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6772da6c..7b7d98a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -263,7 +263,7 @@ ENDIF () # Set system-specific compiler flags IF (CMAKE_SYSTEM_NAME STREQUAL "Darwin") LIST (APPEND SYSFLAGS -D_DARWIN_C_SOURCE) -ELSEIF (CMAKE_SYSTEM_NAME STREQUAL "Linux") +ELSEIF (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android") LIST (APPEND SYSFLAGS -D_GNU_SOURCE -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700) ELSEIF (CMAKE_SYSTEM_NAME STREQUAL "SunOS") LIST (APPEND SYSFLAGS -D__EXTENSIONS__ -D_REENTRANT -D_XOPEN_SOURCE=700)