5

我目前正在尝试通过使用名为 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 库不同?但不是全部?

任何帮助 - 非常感谢。

马科斯

4

2 回答 2

4

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

-E -dM
于 2013-02-28T20:56:11.310 回答
0

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

于 2016-01-15T18:50:06.323 回答