我如何跟踪 FS 被 emscripten 包含的原因?
How can I track the reason why FS is included by emscripten?
我正在将一些 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 支持的内容?
您可以尝试 NO_FILESYSTEM
编译器选项,如 https://kripken.github.io/emscripten-site/docs/optimizing/Optimizing-Code.html#miscellaneous-code-size-tips
中所述
You can use the NO_FILESYSTEM option to disable bundling of filesystem support code (the compiler should optimize it out if not used, but may not always succeed). This can be useful if you are building a pure computational library, for example. See settings.js for more details.
你在命令行中使用的是
emcc -s NO_FILESYSTEM=1 [... other stuff]
Is there a simple way I could track what requires FS support in my code?
我能想到的唯一方法就是重复"bisect"代码。以仍然可以编译的方式注释掉其中的大约一半,并检查输出是否包含文件系统代码。如果不是,则注释掉的一半是导致问题的原因。如果是,则未评论的那一半(可能不完全)是导致问题的原因。您取出导致问题的那一半,然后重复。
通过这种方式,您可以尝试 "zoom in" 导致包含 FS 代码的部分。
我过去曾使用类似的方法来放大我不熟悉的大型 C++ 代码库上的链接器错误。
我正在将一些 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 支持的内容?
您可以尝试 NO_FILESYSTEM
编译器选项,如 https://kripken.github.io/emscripten-site/docs/optimizing/Optimizing-Code.html#miscellaneous-code-size-tips
You can use the NO_FILESYSTEM option to disable bundling of filesystem support code (the compiler should optimize it out if not used, but may not always succeed). This can be useful if you are building a pure computational library, for example. See settings.js for more details.
你在命令行中使用的是
emcc -s NO_FILESYSTEM=1 [... other stuff]
Is there a simple way I could track what requires FS support in my code?
我能想到的唯一方法就是重复"bisect"代码。以仍然可以编译的方式注释掉其中的大约一半,并检查输出是否包含文件系统代码。如果不是,则注释掉的一半是导致问题的原因。如果是,则未评论的那一半(可能不完全)是导致问题的原因。您取出导致问题的那一半,然后重复。
通过这种方式,您可以尝试 "zoom in" 导致包含 FS 代码的部分。
我过去曾使用类似的方法来放大我不熟悉的大型 C++ 代码库上的链接器错误。