问题
cmake 编译的时候, 报如标题的错误
查找原因
这个宏是定义在<inttypes.h> 当中的,这个头文件在toolchain当中很多位置都有,如何确定使用的是哪个?
- 使用
gcc -v test.cpp
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/5
/usr/include/x86_64-linux-gnu/c++/5
/usr/include/c++/5/backward
/usr/lib/gcc/x86_64-linux-gnu/5/include
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/5/include-fixed
/usr/include/x86_64-linux-gnu
/usr/include
gcc会告诉我们它是在哪个路径下找头文件
紧接着在对应的目录里面找到inttypes.h
- 奇怪
/* The ISO C99 standard specifies that these macros must only be
defined if explicitly requested. */
#if !defined __cplusplus || defined __STDC_FORMAT_MACROS
# if __WORDSIZE == 64
# define __PRIu8 "u"
# define PRIu16 "u"
# define PRIu32 "u"
# define PRIu64 __PRI64_PREFIX "u"
在对应的头文件当中,这个宏确实是定义了的,那为什么呢?
这里有一行很重要的注释,看起来是CPP需要这个宏的时候,需要显式的定义__STDC_FORMAT_MACROS,那在我们的makefile里面加上这个宏定义就可以了
/* The ISO C99 standard specifies that these macros must only be
defined if explicitly requested. */
#if !defined __cplusplus || defined __STDC_FORMAT_MACROS