问题集锦:Windows下使用CMake编译cocos2d-x

539 阅读1分钟

CC_FORMAT_PRINTF

#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

__has_attribute(attr)如果 attr 是支持的属性,计算结果为 1

format属性告诉编译器,按照printf, scanf等标准C函数参数格式规则对该函数的参数进行检查。这在我们自己封装调试信息的接口时非常的有用。

将任意输入作为 printf 参数,如果格式化字符串如果类型不匹配,就会获得意外的结果。

因此,如果调用 printf,GCC 和 clang 会根据提供的参数检查格式字符串。 __attribute__((__format__ (__printf__,...)告诉编译器您的参数之一是 printf格式化字符串,并在调用该函数时应用检查。

由于编译器知道在调用函数时会检查格式字符串参数,因此它不会提示您将该参数用作函数内部的格式字符串。

CCApplication-win32.cpp无法找到TIMECAPS

缺少头文件导致,加上就行了

#include <mmsystem.h>

AllocConsole同理 #include <consoleapi.h>

UTF8编码问题

image.png

注意是C/C++命令行选项,不是链接器命令行选项

如果要同时将源字符集和执行字符集设置为 UTF-8,可以使用  /utf-8 编译器选项作为快捷方式。

它等效于命令行上的  /source-charset:utf-8 /execution-charset:utf-8