0

我的目标是使用 emscripten(我通过 emsdk 安装)将我的 C 程序编译为 wasm。它使用 libxml2。我正在按照此处概述的步骤https://github.com/kripken/xml.js/blob/master/script/libxml2使用适当的 emscripten 参数从源代码构建 libxml2。当我运行时emmake make,我收到以下警告和错误:

...

CCLD     libxml2.la
emcc: warning: linking a library with `-shared` will emit a static object file.
This is a form of emulation to support existing build systems.  
If you want to build a runtime shared library use the SIDE_MODULE setting. [-Wemcc]
emcc: warning: ignoring unsupported linker flag: `--version-script=./libxml2.syms` [-Wlinkflags]
wasm-ld: error: cannot open libxml2.so.2: No such file or directory
emcc: error: '/home/willy/emsdk/upstream/bin/wasm-ld -o .libs/libxml2.so.2.9.9 .libs/SAX.o .libs/entities.o .libs/encoding.o -L/home/willy/emsdk/upstream/emscripten/system/local/lib .libs/error.o -L/home/willy/emsdk/upstream/emscripten/system/lib .libs/parserInternals.o -L/home/willy/emsdk/upstream/emscripten/cache/wasm .libs/parser.o .libs/tree.o .libs/hash.o .libs/list.o .libs/xmlIO.o .libs/xmlmemory.o .libs/uri.o .libs/valid.o .libs/xlink.o .libs/HTMLparser.o .libs/HTMLtree.o .libs/debugXML.o .libs/xpath.o .libs/xpointer.o .libs/xinclude.o .libs/nanohttp.o .libs/nanoftp.o .libs/catalog.o .libs/globals.o .libs/threads.o .libs/c14n.o .libs/xmlstring.o .libs/buf.o .libs/xmlregexp.o .libs/xmlschemas.o .libs/xmlschemastypes.o .libs/xmlunicode.o .libs/xmlreader.o .libs/relaxng.o .libs/dict.o .libs/SAX2.o .libs/xmlwriter.o .libs/legacy.o .libs/chvalid.o .libs/pattern.o .libs/xmlsave.o .libs/xmlmodule.o .libs/schematron.o .libs/xzlib.o /home/willy/emsdk/upstream/emscripten/cache/wasm/libc.a libxml2.so.2 --relocatable -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr' failed (1)
make[2]: *** [Makefile:1065: libxml2.la] Error 1
make[2]: Leaving directory '/home/willy/CWasmSandbox/libxml2-2.9.9'
make[1]: *** [Makefile:1484: all-recursive] Error 1
make[1]: Leaving directory '/home/willy/CWasmSandbox/libxml2-2.9.9'
make: *** [Makefile:897: all] Error 2

以我对 emscripten 的有限理解,我唯一能收集到的是它试图访问libxml2.so.2在正常情况下会从libxml2.la. 但是libxml2.so.2没有生成,因为 emscripten 不生成共享对象。这个评价正确吗?我尝试将选项传递CFLAGS="-s SIDE_MODULE=1"make,但它并没有修复错误,并且可能是由于我对构建系统的有限知识而产生的一个愚蠢的想法。我也尝试libxml2.so.2 从以前的安装复制到适当的目录,但没有运气,而且有点愚蠢,因为 emscripten 对 .so 文件没有用处?我的下一步应该是什么?

4

1 回答 1

2

最简单的方法是从共享库中退出。

共享一个(侧模块)有一个重要限制:如果您要在主应用程序中使用线程,它将无法工作。

所以只需更改./script/libxml2

-emconfigure ../libxml2/configure --with-http=no --with-ftp=no --with-python=no --with-threads=no
+emconfigure ../libxml2/configure --with-http=no --with-ftp=no --with-python=no --with-threads=no --enable-shared=no

构建并链接./build/.libs/libxml2.a到您的主应用程序。

于 2021-02-04T07:32:29.197 回答