8

Without it I can't use the libraries needed to connect to the internet, but I don't know what it means:

-D_POSIX_C_SOURCE=200112L

Can anyone explain?

1
  • 1
    Its a feature-request flag for POSIX compilation. See this article. In effect, it is a way your program says "I want POSIX functionality with this level". As more functions are added to revised POSIX standards, the value changes to reflect the changes. You're doing this tells the implementation which "version" of functionality you desire.
    – WhozCraig
    Commented Sep 22, 2013 at 20:57

1 Answer 1

5

POSIX has seen several revisions over time. Each new revision has changed the feature set that it supported.

This macro defines which set of features you want your program will be built with. It influences how the include files are pre-processed, yielding different function prototypes. For example, some libries will check the POSIX_C_SOURCE level at compile time to determine if threads can be used or not. Libraries can use this define to figure out if certain POSIX functions are available for use, or if they have to provide their own implementation.

According to Wikipedia ( https://en.wikipedia.org/wiki/POSIX ), POSIX 2001 equates to the Single UNIX Specification version 3. Maybe the version you mentioned in your original post is the first to define the networking features you need. Functions like listen() and bind() are definitely specified in this standard, while a cursory search does not reveal any mention of them in previous POSIX versions.

If POSIX_C_SOURCE is not specified, the library you are linking to will either make some assumptions about the available feature set, or may complain that it is not defined and give up. Perhaps you perhaps linking in a library that needs this variable to be set correctly?

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.