What does the flag “-D_POSIX_C_SOURCE=200112L” mean?

拥有回忆 提交于 2019-12-13 12:32:13

问题


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:


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?



来源:https://stackoverflow.com/questions/18948661/what-does-the-flag-d-posix-c-source-200112l-mean

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!