In the two days of doing 64-bit porting work, in compiling a certain set of times the wrong is as follows:
ERROR:IMPLICIT declaration of the function ' Pthread_mutexattr_settype '
The reason for this error has been made clear on the Internet, that is, because there is no need to add the header file caused, and then found the function pthread_mutexattr_settype (in <pthread.h> file):
#ifdef __use_unix98/* Return in *kind the mutex KIND attribute in *attr. */extern int pthread_mutexattr_gettype (__const pthread_mutexattr_t *__restrict __attr, int *__restrict __kind) __THR
OW; /* Set The Mutex kind attribute in *attr to kind (either Pthread_mutex_normal, Pthread_mutex_recursive, pthread_mutex_e Rrorcheck, or Pthread_mutex_default).
*/extern int Pthread_mutexattr_settype (pthread_mutexattr_t *__attr, int __kind) __throw; /* Return in *protocol the mutex PROTOCOL attribute in *attr.
*/extern int pthread_mutexattr_getprotocol (__const pthread_mutexattr_t *__restrict __attr, int *__restrict __protocol)
__throw; /* Set The Mutex protocol attribute in *attr to protocol (either Pthread_prio_none, Pthread_prio_inherit, or PTHREAD_PR Io_protect).
*/extern int Pthread_mutexattr_setprotocol (pthread_mutexattr_t *__attr, int __protocol) __throw; /* Return in *prioceiling the mutex prioceiling attribute in *attr. */extern int pthread_mutexattr_getprioceiling (__const pthread_mutexattr_t *__restrict __attr, int *__restrict __prioceiling) __THROW; /* Set The Mutex prioceiling attribute in *attr to prioceiling.
*/extern int pthread_mutexattr_setprioceiling (pthread_mutexattr_t *__attr, int __prioceiling) __throw; #endif
If you do not define the __USE_UNIX98 macro, you will not be able to declare the Pthread_mutexattr_settype, and then you cannot use the function later. Then, after browsing through the data, it is found that the/usr/include/features.h header file has the following code:
#ifdef _xopen_source
# define __use_xopen 1
# if (_xopen_source-0) >= Define __use_xopen_extended 1
# define __use_unix98 1
# undef _largefile_source
# Define _largefile_source 1
# if (_xopen_source-0) >=
# if (_xopen_source-0) & gt;=
# define __USE_XOPEN2K8 1
# endif
# define __use_xopen2k 1
# undef __use_isoc99
# define __USE_ISOC99 1
# endif
# Else
# ifdef _xopen_source_extended
# define __use_xopen_extended 1
# endif
# endif # endif
The code indicates that if the value of the _xopen_source is greater than or equal to 500, then the _use_unix98 is defined to be 1, so we can define _xopen_source as 500.
In this case, the Pthread_mutexattr_settype function in the Pthread.h header file is also declared.
And there's another piece of code in FEATURES.H:
/* If _gnu_source is defined by the user, turn to all features. * *
#ifdef _gnu_source
# undef _isoc99_source
# define _isoc99_source 1
# undef _posix_source
# define _posix_source 1
# undef _posix_c_source
# define _posix_c_source 200809L
# undef _xopen_source #
define _xopen_source #
undef _xopen_source_extended
# Define _xopen_source_extended 1
# undef _largefile64_source
# define _largefile64_source 1
# undef _bsd_source
# define _bsd_source 1
# undef _svid_source
# define _svid_ SOURCE 1
# undef _atfile_source
# define _atfile_source 1
#endif
That is, once the _gun_source macro is defined, several macros are defined, which define _xopen_source as 700, which satisfies the criteria for defining _gnu_source macros. So I can also define macro _gnu_source.
To sum up, add compilation options at compile time:
-d_xopen_source=500 or-d_gnu_source can be solved.
In fact, there is another way to solve the error:implicit declaration of the ' Pthread_mutexattr_settype ' error, which is to compile the option "- Werror-implicit-function-declaration "can be removed, but it is not recommended to remove this option.
All bloggers have been transferred from private blog Joe's personal blog, thank you for your attention.