0

我是使用 emscripten 的新手,在编译 cpp 文件时遇到错误。

我有 iae.cpp:

bool IsAlmostEqual(double A, double B)
{
  //http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
  long long aInt = reinterpret_cast<long long&>(A);
  if (aInt < 0) aInt = -9223372036854775808LL - aInt;
  long long bInt = reinterpret_cast<long long&>(B);
  if (bInt < 0) bInt = -9223372036854775808LL - bInt;
  return (std::abs(aInt - bInt) <= 10000);
}

我尝试使用 emscripten 编译它:

emcc iae.cpp

但它会产生以下警告和错误:

INFO     root: (Emscripten: Running sanity checks)
WARNING  root: java does not seem to exist, required for closure compiler. -O2 and above will fail. You need to define JAVA in ~/.emscripten
iae.cpp:5:27: warning: integer constant is so large that it is unsigned
    if (aInt < 0) aInt = -9223372036854775808LL - aInt;
                          ^
iae.cpp:7:27: warning: integer constant is so large that it is unsigned
    if (bInt < 0) bInt = -9223372036854775808LL - bInt;
                          ^
iae.cpp:8:13: error: use of undeclared identifier 'std'
    return (std::abs(aInt - bInt) <= 10000);
            ^
2 warnings and 1 error generated.
ERROR    root: compiler frontend failed to generate LLVM bitcode, halting

如何摆脱这些警告和错误,甚至可以IsAlmostEqual()使用 emscripten 进行编译?

4

1 回答 1

1

好像你

  1. 错过了一个包含到<cstdlib>
  2. 尝试使用 Javascript 本身不支持的 64 位值。您可以这样做,但只能以牺牲性能为代价。阅读https://github.com/kripken/emscripten/wiki/CodeGuidelinesAndLimitations以获得指导。
于 2014-02-01T08:51:38.487 回答