Symbol visibility problems with -std=

Pavel Fedin
Wed May 13 10:21:23 GMT 2020

 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);
        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
 Isn't this a Cygwin bug? By the way, clang does not suffer from this problem.

Kind regards,
Pavel Fedin
Senior Engineer
Samsung Electronics Research center Russia

More information about the Cygwin mailing list