Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the flag "-D_POSIX_C_SOURCE=200112L" mean?

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?

like image 962
2013Asker Avatar asked Nov 02 '22 14:11

2013Asker


1 Answers

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?

like image 59
BareMetalCoder Avatar answered Nov 15 '22 08:11

BareMetalCoder