{"id":2069,"date":"2024-11-27T12:52:46","date_gmt":"2024-11-27T04:52:46","guid":{"rendered":"https:\/\/blog.quantoyo.com\/?p=2069"},"modified":"2024-11-27T12:52:46","modified_gmt":"2024-11-27T04:52:46","slug":"emcc-%e7%9b%b8%e9%97%9c%e6%8c%87%e4%bb%a4","status":"publish","type":"post","link":"https:\/\/blog.quantoyo.com\/?p=2069","title":{"rendered":"emcc \u76f8\u95dc\u6307\u4ee4"},"content":{"rendered":"\n<p>\u6574\u7406\u9019\u6b21\u4f7f\u7528\u5230\u7684\u6307\u4ee4<\/p>\n\n\n\n<!--more-->\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background has-small-font-size\"><code>\u4f7f\u7528\u524d\u8981\u5148\u914d\u7f6e\n    cd ~\/emsdk\n    .\/emsdk install latest\n    .\/emsdk activate latest\n    source ~\/emsdk\/emsdk_env.sh\n\n\u7dca\u63a5\u8457\u4e0d\u5e36\u4efb\u4f55\u524d\u7db4\u7684\u5c31\u662f\u8981\u7de8\u8b6f\u7684\u6a94\u6848 ex. emcc quanto.c -o quanto.js\n#\u5e6b\u52a9\u6587\u4ef6\nemcc --help\n#emcc\u7248\u672c\nemcc --version\n#\u4e0d\u512a\u5316(\u9810\u8a2d\uff0cdebug\u7528)\n-O0\n#\u512a\u5316\u7de8\u8b6f\n-O1\n  \u7b2c\u4e00\u968e\u512a\u5316\uff0c\u503c\u5f97\u6ce8\u610f\u7684\u662f\u6703\u5c07exception \u76f8\u95dc\u7684\u90e8\u5206disable (-s ALIASING_FUNCTION_POINTERS=1)\n  \u53ef\u4ee5\u85c9\u7531\u4f7f\u7528\u4e0b\u5217\u6307\u4ee4\u6253\u958b -s ALIASING_FUNCTION_POINTERS=0\n-O2\n  \u591a\u4e86javascript \u7684\u512a\u5316(\u7522\u54c1\u63a8\u85a6\u4f7f\u7528)\n-O3\n  \u72a7\u7272\u6027\u80fd\uff0c\u6e1b\u5c11\u6a94\u6848\u5927\u5c0f(\u7522\u54c1\u63a8\u85a6\u4f7f\u7528)\n-Os\n  \u72a7\u7272\u66f4\u591a\u6027\u80fd\uff0c\u6e1b\u5c11\u66f4\u591a\u6a94\u6848\u5927\u5c0f\n-Oz\n  \u72a7\u7272\u66f4\u66f4\u591a\u6027\u80fd\uff0c\u6e1b\u5c11\u66f4\u66f4\u591a\u6a94\u6848\u5927\u5c0f\n\n# -s \u53c3\u6578\n-s WASM=0\n  \u751f\u6210asm.js\n-s WASM=1\n  \u751f\u6210.wasm\u683c\u5f0f(\u9810\u8a2d)\n-s WASM=2\n  \u5169\u500b\u90fd\u751f\u6210\n-s INITIAL_MEMORY=33554432\n  \u9810\u8a2d\u8a18\u61b6\u9ad4\u5927\u5c0f = 32 * 1024 * 1024 bytes =32 MB\n-s MAXIMUM_MEMORY=16777216\n  \u6700\u5927\u8a18\u61b6\u9ad4\u5927\u5c0f\uff08\u4e0d\u4e00\u5b9a\u8981\u8a2d\u5b9a\uff09\n-s ALLOW_MEMORY_GROWTH=1\/0\n  0:\u4e0d\u5141\u8a31\u8a18\u61b6\u9ad4\u8b8a\u5927(\u9810\u8a2d)\n  1:\u5141\u8a31\u8a18\u61b6\u9ad4\u8b8a\u5927\n-s EXPORTED_FUNCTIONS\n  \u5c07\u6703\u5c0e\u51fa\u7684function name\uff0c\u524d\u9762\u6703\u52a0\u500b\u5e95\u7dda (\u81ea\u5df1\u5beb\u7684\uff0c\u6216\u8005C\/ C++ \u5167\u5efa\u7684)\n  malloc \/ free \u662f\u70ba\u4e86js \u53ef\u4ee5\u914d\u7f6e\u8a18\u61b6\u9ad4\n-s EXPORTED_RUNTIME_METHODS\n  js \u4e0a\u53ef\u4ee5\u4f7f\u7528\u7684 emcc \u63d0\u4f9b\u7684function (\u5167\u5efa\u7684)\n    ccall\uff1ajs\u62ff\u4f86\u547c\u53eb c\u88e1\u9762\u7684\u51fd\u6578\uff0c\u9700\u8981\u914d\u7f6e returnTypes \u8ddf argTypes\n    cwrap\uff1a\u540c\u4e0a\uff0c\u4f46\u662f\u53ef\u4ee5\u5305\u88dd\u6210js function\n    UTF8ToString\uff1a\u5c07\u6307\u6a19\u8f49js \u7684\u5b57\u4e32\n    \u985e\u4f3c\u7684\u9084\u6709\u5f88\u591a \u53c3\u8003\uff1a<a href=\"https:\/\/emscripten.org\/docs\/api_reference\/preamble.js.html\">https:\/\/emscripten.org\/docs\/api_reference\/preamble.js.html<\/a>\n--bind\n-std=c++11\n  \u9019\u662f\u5728\u5bebC++\u6642\u6703\u9700\u8981\u6dfb\u52a0\u7684\uff0c\u5426\u5247\u9810\u8a2d\u662fC \u7684\u7de8\u8b6f\u5668\n  <\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6574\u7406\u9019\u6b21\u4f7f\u7528\u5230\u7684\u6307\u4ee4<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[299,3],"tags":[322,323,47,319,320,43,321,175],"class_list":["post-2069","post","type-post","status-publish","format-standard","hentry","category-duty","category-technology","tag-asm","tag-asm-js","tag-c","tag-emcc","tag-emsdk","tag-wasm","tag-321","tag-175"],"_links":{"self":[{"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=\/wp\/v2\/posts\/2069","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2069"}],"version-history":[{"count":1,"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=\/wp\/v2\/posts\/2069\/revisions"}],"predecessor-version":[{"id":2070,"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=\/wp\/v2\/posts\/2069\/revisions\/2070"}],"wp:attachment":[{"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2069"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2069"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2069"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}