我正在将一些 C++ 代码编译为 emscripten。我注意到 emscripten 包含一大段代码来支持文件系统操作。根据 emscripten 的文档,包含此代码是因为编译后的 C++ 调用了 I/O 函数。否则,它不会在那里。这是文档的相关部分:
Emscripten decides whether to include file system support automatically. Many programs don’t need files, and file system support is not negligible in size, so Emscripten avoids including it when it doesn’t see a reason to. That means that if your C/C++ code does not access files, then the FS object and other file system APIs will not be included in the output. And, on the other hand, if your C/C++ code does use files, then file system support will be automatically included. So normally things will “just work” and you don’t need to think about this at all.
我正在编译的代码不应该做 I/O,我想优化编译后的 javascript 的大小。我努力尝试删除所有 I/O 代码,但必须在某个地方留下一些需要 FS 支持的东西。
有没有一种简单的方法可以跟踪代码中需要 FS 支持的内容?
最佳答案
Is there a simple way I could track what requires FS support in my code?
我能想到的唯一办法就是反复“平分”代码。以仍然可以编译的方式注释掉其中的大约一半,并检查输出是否包含文件系统代码。如果不是,则注释掉的一半是导致问题的原因。如果是,则未评论的那一半(可能不完全)是导致问题的原因。您取出导致问题的那一半,然后重复。
通过这种方式,您可以尝试“放大”导致包含 FS 代码的那部分。
我过去曾使用类似的方法来放大我不熟悉的大型 C++ 代码库上的链接器错误。
关于javascript - 我如何跟踪 FS 被 emscripten 包含的原因?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38641318/