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 c99, iso9899:1999, c11, iso9899:2011, C++98, C++03, c++11, c++14, and c++17. For more information, see “Options Controlling C Dialect” in the gcc documentation at https://gcc.gnu.org/onlinedocs/.
There are additional variants of this option that enable vendor-specific compiler extensions: gnu99, gnu11, gnu++98, gnu++11, gnu++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= | -Y | Library |
---|---|---|
libc++ | _cxx | LLVM C++ |
libstdc++ | _gpp | GNU C++ |
For more information, see the -Y option below.
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.