【问题标题】:Best way to determine what macros are defined by clang and cmake确定 clang 和 cmake 定义了哪些宏的最佳方法
【发布时间】:2013-02-27 19:25:47
【问题描述】:

我目前正在尝试通过使用名为 Emscripten 的惊人 LLVM->Javascript 项目将 CGAL 转换为 Javascript。我只是用核心组件来做这个(不是 ImageIO 或 Qt 的东西)

我已经设法通过它的两个依赖项(GMP 和 MPFR)来做到这一点。令我惊讶的是,我能够将 C 测试类编译为 Javascript(针对以位码形式生成的 LLVM 库),在 nodejs 中运行的输出与本机结果精确匹配。

所有其他依赖项都是仅标头(Eigen,Boost),除了一个 - libboost-thread。现在,显然 JS 是单线程的,所以希望能够从 CGAL 代码中删除它。幸运的是,我已经定义了一个 CGAL_HAS_NO_THREADS 宏:

add_definitions( -DCGAL_HAS_NO_THREADS=1 )

这似乎是作为 -D 选项传递给命令行的

但是,当我尝试使用 clang 编译时(通过设置 clang 等的 Emscripten 工具运行 cmake 进行设置),我得到了一大堆错误,这些错误在使用 gcc 编译时没有得到,这似乎是双重:

1) 首先是这样的:

    #if defined (__GLIBC__)
#  include <endian.h>
#  if (__BYTE_ORDER == __LITTLE_ENDIAN)
#    define CGAL_LITTLE_ENDIAN
#  elif (__BYTE_ORDER == __BIG_ENDIAN)
#    define CGAL_BIG_ENDIAN
#  else
#    error Unknown endianness
#  endif
#elif defined(__sparc) || defined(__sparc__) \
   || defined(_POWER) || defined(__powerpc__) \
   || defined(__ppc__) || defined(__hppa) \
   || defined(_MIPSEB) || defined(_POWER) \
   || defined(__s390__)
#  define CGAL_BIG_ENDIAN
#elif defined(__i386__) || defined(__alpha__) \
   || defined(__x86_64) || defined(__x86_64__) \
   || defined(__ia64) || defined(__ia64__) \
   || defined(_M_IX86) || defined(_M_IA64) \
   || defined(_M_ALPHA) || defined(_WIN64)
#  define CGAL_LITTLE_ENDIAN
#else
#  error Unknown endianness
#endif

这给了我一个“未知字节顺序”错误。我认为是由于 clang 编译器没有定义 GLIBC 宏?

另一个是这样的:

In file included from /home/marcosscriven/sources/openscadjs/build/CGAL-4.1/src/CGAL/all_files.cpp:1:
In file included from /home/marcosscriven/sources/openscadjs/build/CGAL-4.1/src/CGAL/Random.cpp:25:
In file included from /home/marcosscriven/sources/openscadjs/build/CGAL-4.1/include/CGAL/Random.h:30:
In file included from /home/marcosscriven/sources/openscadjs/build/CGAL-4.1/include/CGAL/basic.h:44:
In file included from /home/marcosscriven/sources/openscadjs/build/CGAL-4.1/include/CGAL/number_type_basic.h:77:
In file included from /home/marcosscriven/sources/openscadjs/build/CGAL-4.1/include/CGAL/FPU.h:60:
In file included from /usr/lib/gcc/i686-linux-gnu/4.7/../../../../include/c++/4.7/fenv.h:33:
In file included from /usr/lib/gcc/i686-linux-gnu/4.7/../../../../include/c++/4.7/i686-linux-gnu/bits/c++config.h:414:
In file included from /usr/lib/gcc/i686-linux-gnu/4.7/../../../../include/c++/4.7/i686-linux-gnu/bits/os_defines.h:40:
/home/marcosscriven/sources/includes/features.h:324:10: fatal error: 'bits/predefs.h' file not found
#include <bits/predefs.h>

这似乎取决于使用不同的补丁(或一组路径,或路径顺序)来查找库。

现在显然我可以一点一点地破解这两件事 - 但我猜这不是“正确”的方式。

我遇到的麻烦是知道在运行 clang(甚至 gcc)时定义了哪些宏?我也不确定 /usr/include/ 的根目录中包含的所有内容是什么?

我知道其中 一些 是 GNUC,并且这在某种程度上与 std libc 和 libcxx 库不同?但不是全部?

任何帮助 - 非常感谢。

马科斯

【问题讨论】:

标签: c++ ide llvm clang emscripten


【解决方案1】:

把它放在命令行上会输出一个已定义宏的列表:

-E -dM

【讨论】:

  • 另外,-E -dD 将输出宏定义和周围的代码(如果您需要找到定义宏的头文件,这很有用)。
【解决方案2】:

您是否尝试过使用 -DBOOST_NO_THREADS ?你最终是否设法将 CGAL 编译为 javascript?

【讨论】:

猜你喜欢
  • 2015-08-06
  • 2016-12-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多