c++ - OS X 上的快速格式化

标签 c++ fastformat

在阅读了一些有关 FastFormat 的内容后,我决定将其下载并安装到我运行 OS X 10.8 的 Macbook Pro 上。我成功地构建了 FastFormat,并运行了性能测试。然后我写了一个小测试来检查它是否有效:

#include <cstdlib>
#include <fastformat/fastformat.hpp>
#include <fastformat/sinks/ostream.hpp>

int main()
{
    return EXIT_SUCCESS;
}

在使用 g++-4.7 编译它(并确保所有包含路径都是正确的)后,我从 PlatformSTL 得到了编译时错误,如下所示。

error: #error Operating system not discriminated. Only UNIX and Windows are currently recognised by PlatformSTL
error: #error Operating system not discriminated

我试图通过手动定义 unixPLATFORMSTL_OS_IS_UNIX 来抑制这些错误,但随后我收到了这些链接器错误:

Undefined symbols for architecture x86_64:
  "_fastformat_exitProcess", referenced from:
      fastformat::fastformat_initialiser::fastformat_initialiser() in ccMqErni.o
  "_fastformat_getInitCodeString", referenced from:
      fastformat::fastformat_initialiser::record_init_failure_(int)    in ccMqErni.o
  "_fastformat_init", referenced from:
      fastformat::fastformat_initialiser::fastformat_initialiser() in ccMqErni.o
  "_fastformat_uninit", referenced from:
      fastformat::fastformat_initialiser::~fastformat_initialiser() in ccMqErni.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

OS X 是否支持 FastFormat,如果支持,我做错了什么?

最佳答案

Mac OS X 不提供 UNIX (或 unix , __unix__ , __unix )宏 PlatformSTL试图检测。添加 defined(__MACH__) 行后,我能够编译您的示例platformstl.h 中的声明像这样(第 154 行):

#if defined(unix) || \ 
    defined(UNIX) || \ 
    defined(__unix__) || \ 
    defined(__unix) || \ 
    defined(__MACH__) 
# define PLATFORMSTL_OS_IS_UNIX

要抑制 undefined symbol 错误,您可以定义宏 FASTFORMAT_NO_AUTO_INIT :

g++ -I<path to fastformat and stlsoft headers> -DFASTFORMAT_NO_AUTO_INIT main.cpp

关于c++ - OS X 上的快速格式化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13717936/

相关文章:

c++ - 错误: expected ‘}’ at end of input -- when there is one

c++ - 定义类中声明的变量的范围(C++)?

c++ - 类的 begin() 方法编译错误

c++ - 如何判断参数何时来自硬编码数字?

c++ - 插入排序优化

c++ - 如何保证接受无限数量参数的函数的类型安全?

c++ - FastFormat 有 'catch' 吗?