1

A program can fail to compile in Cygwin using gcc -std=c++11. Headers compile OK (unless, like boost/asio.hpp, they try to use a missing definition). Now, because Cygwin's #ifdef macros bypass some function definitions in the c++11 environment, a programs might not. This does not occur when the same source files are similarly compiled on Fedora Linux.

This example program fails to compile using the gcc -std=c++11 option:

#include <boost/asio.hpp>
int main() { return 0; }

I first encountered this by discovering that the above program didn't compile, and then found even more similar problems when recompiling existing code using the updated standard.

The include sections I've found to be broken are listed in the reply.

[edited to correct typos.]

2
  • Why aren't you using -std=gnu++11 instead? Commented Dec 13, 2016 at 22:39
  • Thanks @MarkGlisse. I used the c++11 option I found in the documentation. I didn't realize there was another way of specifying the new standard until you pointed it out.(Your method is better. The problem won't recur when you upgrade or reinstall boost.) Commented Jan 31, 2017 at 16:17

2 Answers 2

2

Here's a workaround you can use until the Cygwin include library is updated:

In your source code, include

#define _GNU_SOURCE

before any other includes. This workaround is not needed in Fedora Linux, only in the Cygwin environment and then only with the -std= compiler option.

This fixes:

#include <boost/asio.hpp> // (Because it uses sigfillset from sys/signal.h)
#include <sys/signal.h>   // sigfillset and others declared nearby
#include <sys/types.h>    // u_int and other __MISC_VISIBLE typedefs
#include <stdio.h>        // at least fileno
#include <string.h>       // at least strdup

and possibly other glitches I haven't discovered. This could also be fixed by simply modifying /usr/include/sys/features.h, adding

#ifndef _GNU_SOURCE // LOCAL WORK-AROUND
#define _GNU_SOURCE
#endif

near the beginning of the file. While this works for casual library users, it's not the method Cygwin developers will use.

Sign up to request clarification or add additional context in comments.

3 Comments

_GNU_SOURCE is the default. Why using gcc -std=c++11 ? Or is C or is C++ , I do not understand calling the c ompiler with a C++ standard.
It turns out that I was actually using c++ -std=c++11. However, the same failure occurs whether using gcc, c++, or g++. If you google "gnu c++ compiler," gcc is what comes up. It is a c++ compiler.
/usr/bin/gcc and /usr/bin/g++ are two different compilers for two different languages. They are related, as the languages are related, but not identical. It is not clear to me if you have tested or not without -std=c++11
1

Use -std=gnu++11 instead of -std=c++11 with Cygwin.

With Cygwin I've found -std=c++11 seems to exclude GNU extensions and causes all kinds of issues with Boost and POSIX headers.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.