问题1
#if defined(__GNUC__) && (__GNUC__ >= 4) #define CC_FORMAT_PRINTF(formatPos, argPos) __attribute__((__format__(printf, formatPos, argPos))) #elif defined(__has_attribute) #if __has_attribute(format) #define CC_FORMAT_PRINTF(formatPos, argPos) __attribute__((__format__(printf, formatPos, argPos))) #endif // __has_attribute(format) #else #define CC_FORMAT_PRINTF(formatPos, argPos) #endif 复制代码
- CCConsole.lh
void CC_DLL log(const char * format, ...) CC_FORMAT_PRINTF(1, 2); 复制代码
以上的代码cmake编译一直提示缺少{,把CC_FORMAT_PRINTF的#else的情况补充完整就行了
代码分析
__has_attribute(attr)如果 attr 是支持的属性,计算结果为 1
format属性告诉编译器,按照printf, scanf等标准C函数参数格式规则对该函数的参数进行检查。这在我们自己封装调试信息的接口时非常的有用。
将任意输入作为 printf 参数,如果格式化字符串如果类型不匹配,就会获得意外的结果。
因此,如果调用 printf,GCC 和 clang 会根据提供的参数检查格式字符串。 __attribute__((__format__ (__printf__,...)告诉编译器您的参数之一是 printf格式化字符串,并在调用该函数时应用检查。
由于编译器知道在调用函数时会检查格式字符串参数,因此它不会提示您将该参数用作函数内部的格式字符串。
问题2
CCApplication-win32.cpp无法找到TIMECAPS,缺少头文件导致,加上就行了#include <mmsystem.h>
AllocConsole同理 #include <consoleapi.h>
编码问题
网络异常,图片无法展示
|
如果要同时将源字符集和执行字符集设置为 UTF-8,可以使用 /utf-8 编译器选项作为快捷方式。
它等效于命令行上的 /source-charset:utf-8 /execution-charset:utf-8