From c4119a001e9d4b25347bf07a3611340615cfa727 Mon Sep 17 00:00:00 2001 From: Neui Date: Thu, 7 Nov 2019 20:31:10 +0100 Subject: [PATCH 1/3] Define "feature macros" for symlink MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Define _XOPEN_SOURCE and _POSIX_C_SOURCE appropriately in order to be able to use functions such as symlink() on cygwin. Before that it would error while running make about not being able to find a function called "symlink". After looking into the header files, I've found it requires at least one of those macros in order to be defined. The error was: g++ -std=c++11 -DHAVE_CONFIG_H -I. -g -O2 -MT Fileinfo.o -MD -MP -MF .deps/Fileinfo.Tpo -c -o Fileinfo.o Fileinfo.cc Fileinfo.cc: In lambda function: Fileinfo.cc:280:14: error: ‘symlink’ was not declared in this scope return symlink(target.c_str(), filename.c_str()); ^~~~~~~ Fileinfo.cc:280:14: note: suggested alternative: ‘unlink’ return symlink(target.c_str(), filename.c_str()); ^~~~~~~ unlink Additionally, man 2 symlink (on Ubuntu 18.04) says, it'll be defined for: _XOPEN_SOURCE >= 500 || _POSIX_C_SOURCE >= 200112L || /* Glibc versions <= 2.19: */ _BSD_SOURCE However, defining _BSD_SOURCE would cause cygwin sys/feature.h to define _DEFAULT_SOURCE, which in turns always redefines _POSIX_C_SOURCE, causing an redefinition warning when the config.h file is processed again. Thus _BSD_SOURCE isn't defined, for now. This is also my first time modifying autoconfig files. I hope I did everything alright. --- configure.ac | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/configure.ac b/configure.ac index be1b2fd..6b70f09 100644 --- a/configure.ac +++ b/configure.ac @@ -56,6 +56,14 @@ AC_CHECK_LIB(nettle,main,,[AC_MSG_ERROR([ and try again. ])]) +dnl make sure to set feature test macros to use symlink +AC_DEFINE([_POSIX_C_SOURCE], [200112L], [Use extra functions such as symlink]) +AC_DEFINE([_XOPEN_SOURCE], [500], [Use extra functions such as symlink]) +dnl Commented out because for some reason cygwin sys/features.h defines +dnl _DEFAULT_SOURCE when _BSD_SOURCE is defined and redefines _POSIX_C_SOURCE, +dnl causing a redefinition warning when it reads the config.h again +dnl AC_DEFINE([_BSD_SOURCE], [1], [Use extra functions such as symlink]) + dnl test for some specific functions AC_CHECK_FUNC(stat,,AC_MSG_ERROR(oops! no stat ?!?)) From 262053bbb2c4e73ac034c6c5c8ce644464d40009 Mon Sep 17 00:00:00 2001 From: Neui Date: Fri, 8 Nov 2019 17:37:48 +0100 Subject: [PATCH 2/3] Use AH_VERBATIM instead to use #ifndef It's to prevent redefinition warnings on systems other than cygwin such as Ubuntu. --- configure.ac | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index 6b70f09..8972055 100644 --- a/configure.ac +++ b/configure.ac @@ -57,12 +57,27 @@ AC_CHECK_LIB(nettle,main,,[AC_MSG_ERROR([ ])]) dnl make sure to set feature test macros to use symlink -AC_DEFINE([_POSIX_C_SOURCE], [200112L], [Use extra functions such as symlink]) -AC_DEFINE([_XOPEN_SOURCE], [500], [Use extra functions such as symlink]) -dnl Commented out because for some reason cygwin sys/features.h defines -dnl _DEFAULT_SOURCE when _BSD_SOURCE is defined and redefines _POSIX_C_SOURCE, -dnl causing a redefinition warning when it reads the config.h again -dnl AC_DEFINE([_BSD_SOURCE], [1], [Use extra functions such as symlink]) +AH_VERBATIM([_POSIX_C_SOURCE], + [/* Make "extra" functions available such as symlink() */ + #ifndef _POSIX_C_SOURCE + # define _POSIX_C_SOURCE 200112L + #endif]) +AH_VERBATIM([_XOPEN_SOURCE], + [/* Make "extra" functions available such as symlink() */ + #ifndef _XOPEN_SOURCE + # define _XOPEN_SOURCE 500 + #endif]) +dnl defining _BSD_SOURCE causes a deprecation warning to use _DEFAULT_SOURCE instead +dnl AH_VERBATIM([_BSD_SOURCE], +dnl [/* Make "extra" functions available such as symlink() */ +dnl #ifndef _BSD_SOURCE +dnl # define _BSD_SOURCE 1 +dnl #endif]) +AH_VERBATIM([_DEFAULT_SOURCE], + [/* Make "extra" functions available such as symlink() */ + #ifndef _DEFAULT_SOURCE + # define _DEFAULT_SOURCE 1 + #endif]) dnl test for some specific functions AC_CHECK_FUNC(stat,,AC_MSG_ERROR(oops! no stat ?!?)) From 905a40d3af697dd78112264a58664b17bd71da8b Mon Sep 17 00:00:00 2001 From: Neui Date: Sat, 14 Aug 2021 21:34:11 +0200 Subject: [PATCH 3/3] Remove unused defines for extra system functions It was determined that just defining _POSIX_C_SOURCE is enough to let symlink() be defined. --- configure.ac | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/configure.ac b/configure.ac index 8972055..d1cdd2d 100644 --- a/configure.ac +++ b/configure.ac @@ -62,22 +62,6 @@ AH_VERBATIM([_POSIX_C_SOURCE], #ifndef _POSIX_C_SOURCE # define _POSIX_C_SOURCE 200112L #endif]) -AH_VERBATIM([_XOPEN_SOURCE], - [/* Make "extra" functions available such as symlink() */ - #ifndef _XOPEN_SOURCE - # define _XOPEN_SOURCE 500 - #endif]) -dnl defining _BSD_SOURCE causes a deprecation warning to use _DEFAULT_SOURCE instead -dnl AH_VERBATIM([_BSD_SOURCE], -dnl [/* Make "extra" functions available such as symlink() */ -dnl #ifndef _BSD_SOURCE -dnl # define _BSD_SOURCE 1 -dnl #endif]) -AH_VERBATIM([_DEFAULT_SOURCE], - [/* Make "extra" functions available such as symlink() */ - #ifndef _DEFAULT_SOURCE - # define _DEFAULT_SOURCE 1 - #endif]) dnl test for some specific functions AC_CHECK_FUNC(stat,,AC_MSG_ERROR(oops! no stat ?!?))