Am 13.05.2020 um 12:21 schrieb Pavel Fedin via Cygwin:
  Hello everyone!

  While compiling various software packages for Cygwin i notice that very often 
i have to add something like #define _GNU_SOURCE to
them in order to compile correctly. Meanwhile on Linux they compile with no 
problems at all. I've narrowed it down to -std=???
option using a simple test case:
--- cut test.cpp ---
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
         char *p = strdup("hello");

         printf("%s\n", p);
         free(p);
         return 0;
}
--- cut test.cpp ---

$ g++ test.cpp -o test - compiles OK
$ g++ test.cpp -o test -std=c++14 - error: 'strdup' was not declared in this 
scope; did you mean 'strcmp'?

  By printing out predefined macros (-dM -E) i found out that -std=something option adds 
" #define __STRICT_ANSI__ 1" to builtin
macros, but removes all *_SOURCE definitions, so _DEFAULT_SOURCE is not 
triggered any more.
  I've compared the behavior with Linux system. On Linux -std=c++14 also 
defines __STRICT_ANSI__, but various *_SOURCE macros are not
omitted.
  Isn't this a Cygwin bug? By the way, clang does not suffer from this problem.

Kind regards,
Pavel Fedin


strdup is an extension of C standard

so strictly behaviour of Cgywin is correct, see

 /usr/include/sys/features.h

for details



--
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

Reply via email to