Emscripten:algorithm.h 找不到文件

Emscripten: algorithm.h file not found

我正在尝试编译以下代码:

#include<stdio.h>
#include <algorithm.h>

int main() {
  printf("hello, world!\n");
  return 0;
}

但是当我 运行 emcc test.c -o test.html 我得到以下错误:

fatal error: 'algorithm.h' file not found

当我删除导入 algorithm.h 的行时,代码编译完美。

为什么会这样?我的印象是 algorithm.h 是标准库的一部分。

编辑:

我将文件名从 test.c 更改为 test.cpp,我将 header 名称更新为 <cstdio><algorithms>,并且我还设置 -std=c++11 现在可以使用了。

如果这是 C++ 使用

#include <cstdio>

代替stdio.h

#include <algorithm>

改为

标准 C++ 中没有 <algorithm.h> - 只有 <algorithm>

同样在 C++ 中,stdio header 可从 <cstdio><stdio.h> 访问以获得兼容性。

此外,由于您包含算法,文件扩展名应为 .cc.cpp 而不是 .c 否则 emcc/gcc 会将其视为 C 源而不是一个 C++ 的。