【发布时间】:2021-05-28 22:28:54
【问题描述】:
我有一个 webassembly 项目,我想用 emscripten 构建它。
我在我的项目中克隆了stbi image header files,然后尝试编译所有内容。
我的main.c 看起来像这样:
#include "stb_image.h"
#include <emscripten.h>
...
EMSCRIPTEN_KEEPALIVE
void my_func(int test) {
// I need some functions from stbi image
stbi_load_from_memory(...)
};
所以我尝试的第一件事是emcc main.c
我收到第一个错误:
error: undefined symbol: stbi_write_jpg_to_func (referenced by top-level compiled C/C++ code)
warning: Link with `-s LLD_REPORT_UNDEFINED` to get more information on undefined symbols
warning: To disable errors for undefined symbols use `-s ERROR_ON_UNDEFINED_SYMBOLS=0`
warning: _stbi_write_jpg_to_func may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
Error: Aborting compilation due to previous errors
然后我尝试先编译库,如the docs中所述
第一个命令emcc stb_image.h main.c -c,我收到警告。
clang-11: warning: treating 'c-header' input as 'c++-header' when in C++ mode, this behavior is deprecated [-Wdeprecated]
当我尝试使用它的结果时,它总是失败。
如果我反其道而行之:emcc main.c stb_image.h -c 这次我得到一个错误:
emcc: error: cannot mix precompile headers with non-header inputs: ['main.c', 'stb_image.h'] : main.c
所以我不知道如何才能正确编译它。
我对gcc、linking和emcc了解不多:
我的 makefile 必须看起来如何才能构建它?
有可能吗?
【问题讨论】:
标签: c linker header emscripten