c++ - 确定 clang 和 cmake 定义了哪些宏的最佳方法

标签 c++ ide llvm clang emscripten

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

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

所有其他依赖项都是仅 header (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

这给了我一个“Unknown Endianness”错误。我假设是由于 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 使用不同的补丁(或路径集,或路径顺序)来查找库。

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

我遇到的问题是在运行 clang(或什至 gcc)时非常清楚定义了哪些宏?我也不确定/usr/include/的根目录中包含的所有内容是什么?

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

任何帮助 - 非常感谢。

马科斯

最佳答案

将其放在命令行上将输出已定义宏的列表:

-E -dM

关于c++ - 确定 clang 和 cmake 定义了哪些宏的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15120624/

相关文章:

C++如何避免浮点运算错误

c++ - 为什么数组元素的平均打印速度比C++中单个对象的打印速度慢?

php - 一步一步: How to do Xdebug troubleshooting connection to client IDE

c++ - 防止 clang 扩展聚合类型的参数?

c++ - 两个 CUDA 内核复制内存 - 为什么速度不同?

c++ - 零延迟麦克风环回、侧音

java - Android Studio 隐藏不正确的 "Probable bug"

ide - 如何在 IntelliJ IDEA 中的当前文件上运行外部工具

c++ - "Live"代码和使用 C++ 和 LLVM JIT 的快速原型(prototype)制作?

macos - 如何在我的新 MacBook Pro(使用 Mac OS Catalina)上安装 openMP?