我找到了一个解决方案,可用于以下Hello World计划,从浓缩咖啡中提供的Micro RuntimeRepository
:在路径上的目录中是程序,以及# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
WAMR_DIR=${PWD}/../../..
echo "Build wasm app .."
/opt/wasi-sdk/bin/clang -O3 \
-z stack-size=4096 -Wl,--initial-memory=65536 \
-o test.wasm main.c \
-Wl,--export=main -Wl,--export=__main_argc_argv \
-Wl,--export=__data_end -Wl,--export=__heap_base \
-Wl,--strip-all,--no-entry \
-Wl,--allow-undefined \
-nostdlib \
echo "Build binarydump tool .."
rm -fr build && mkdir build && cd build
cmake ../../../../test-tools/binarydump-tool
make
cd ..
echo "Generate test_wasm.h .."
./build/binarydump -o test_wasm.h -n wasm_test_file test.wasm
echo "Done"
:优化级别3 GOHERE
有关更多信息
-O3
:链接器参数,是线性内存的区域的辅助堆栈大小,必须小于初始内存大小:线性内存的初始大小,必须是65536-Wl,--initial-memory
:将输出写入
-o
-Wl,--export=main
-Wl,--export=__main_argc_argv
-Wl,--export=__data_end
:我不知道,为什么我们需要这些,但是我发现了这个redditpost
-Wl,--export=__data_end
-Wl,--strip-all,--no-entry
:允许链接的二进制中的未定义符号。我们需要这个,因为在某个时候我们可能希望将功能注入WASM应用程序,因此该应用程序可以调用运行时间外定义的函数。
-Wl,--allow-undefined
:链接时请勿使用标准系统启动文件或库。这是必要的,因为意式浓缩咖啡决定使用Wamr的Libc-Builtin库。