QNX的宏QNX_SOURCE

时间:2021-07-15
本文章向大家介绍QNX的宏QNX_SOURCE,主要包括QNX的宏QNX_SOURCE使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

在qcc编译中宏QNX_SOURCE的作用是会包括POSIX的库函数,如果只加了-std=C++11,但没有QNX_SOURCE就算是包含了头文件#include <unistd.h>等,都是无法使用Linux的POSIX相关库函数,声明等。

add_definitions(-D_QNX_SOURCE)

也可以使用-std=gnu++11替代-std=C++11

-std=language

Specify the language standard. We currently support c99iso9899:1999c11iso9899:2011C++98C++03c++11c++14, and c++17. For more information, see “Options Controlling C Dialect” in the gcc documentation at https://gcc.gnu.org/onlinedocs/.

This option restricts the language libraries (libc, libc++) to the specified ISO standard, which hides any function calls and symbols that aren't part of that standard. To include everything that's defined in the header files, such as functions that are part of the POSIX standard, also use the -D option to define _QNX_SOURCE. See Conforming to standards” in the “Compiling and Debugging” chapter of the QNX Neutrino Programmer's Guide.

There are additional variants of this option that enable vendor-specific compiler extensions: gnu99gnu11gnu++98gnu++11gnu++14, and gnu++17. If you use these variants, _QNX_SOURCE is defined automatically, and some other non-standard functionality of the compiler is enabled; see the gcc documentation. If you don't specify the -std, the defaults are gnu11 and gnu++14 for C and C++, respectively.

-stdlib=library

Select the C++ library type to use. This option maps to the -Y option as follows:

-stdlib=-YLibrary
libc++ _cxx LLVM C++
libstdc++ _gpp GNU C++

For more information, see the -Y option below.

Conforming to standards

The header files supplied with the C library provide the proper declarations for the functions and for the number and types of arguments used with them. Constant values used in conjunction with the functions are also declared. The files can usually be included in any order, although individual function descriptions show the preferred order for specific headers.

If you want to conform to a given language standard, you can use the -std=language option for qcc. This option can cause certain portions of the header files to be omitted, which is likely to cause problems because functions that are defined by POSIX or that are specific to QNX Neutrino won't be defined.

You can then use the qcc -D option to define feature-test macros to specify the portions that you want to include. Here are the most commonly used feature-test macros:

_POSIX_C_SOURCE=version
Include those portions of the header files that relate to the given POSIX standard. For example, _POSIX_C_SOURCE=200809L specifies the IEEE Standard Portable Operating System Interface for Computer Environments - POSIX 1003.1-2008.
_FILE_OFFSET_BITS=64
Make the libraries use 64-bit file offsets.
_LARGEFILE64_SOURCE
Include declarations for the functions that support large files (those whose names end with 64).
_QNX_SOURCE
Include everything defined in the header files. This is defined by default if you don't specify a language standard.

Feature-test macros may be defined on the command line, or in the source file before any header files are included. The latter is illustrated in the following example, in which a POSIX-conforming application is being developed.

#define _POSIX_C_SOURCE 200809L
#include <limits.h>
#include <stdio.h>
   …
#if defined(_QNX_SOURCE)
  #include "non_POSIX_header1.h"
  #include "non_POSIX_header2.h"
  #include "non_POSIX_header3.h"
#endif

You can also set the POSIXLY_CORRECT environment variable to 1. This environment variable is used by Unix-style operating systems to alter behavior to comply with POSIX where it's different from the OS's default behavior. It's a de facto standard that isn't defined by POSIX.

For example, if POSIXLY_CORRECT is set, functions that check the length of a pathname do so before removing any redundant . and .. components. If POSIXLY_CORRECT isn't set, the functions check the length after removing any redundant components.

原文地址:https://www.cnblogs.com/sciapex/p/15016401.html