简体   繁体   English

Emscripten Link静态库错误:wasm蒸汽编译失败:导入“ env.getTempRet0”

[英]Emscripten Link static Library error: wasm steaming compile fail: Import 'env.getTempRet0'

There is an error when I tried to link my wasm code with static libraries, Grassroot DICOM library. 当我尝试将wasm代码与静态库Grassroot DICOM库链接时出现错误。

First of all, I compile Grassroot DICOM using cmake with external toolchain and cmake found from /1.38.14/cmake/Modules/Platform 首先,我使用带有外部工具链的cmake和从/1.38.14/cmake/Modules/Platform中找到的cmake来编译Grassroot DICOM。

using Windows 10 with Visual Studio 2017 and Windows 8.1 SDK. 将Windows 10与Visual Studio 2017和Windows 8.1 SDK结合使用。

After compile is done. 编译完成后。 I got static link files 我有静态链接文件

libgdcmcharls.a
libgdcmCommon.a
libgdcmDICT.a
libgdcmDSED.a
....

Then I linked those files to my code using flag 然后我使用标志将这些文件链接到我的代码

-L<PATH-to-library>
-lgdcmcharls -lgdcmCommon -lgdcmDICT -lgdcmDSED ...

also use: 还可以使用:

-s WASM=1 -s SIDE_MODULE=1 -s EXPORT_ALL=1 

The libraries can link and cannot compile. 这些库可以链接,不能编译。 The errors are 错误是

multiprocessing.pool.RemoteTraceback: """ Traceback (most recent call last): File "C:\\Users\\WORK\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\multiprocessing\\pool.py", line 121, in worker result = (True, func(*args, **kwds)) File "C:\\Users\\IwI\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\multiprocessing\\pool.py", line 44, in mapstar return list(map(*args)) File "C:\\workspace\\emsdk\\emscripten\\1.38.14\\tools\\shared.py", line 1363, in extract_archive_contents assert not os.path.dirname(f) AssertionError . multiprocessing.pool.RemoteTraceback:“”“回溯(最近一次调用最近):文件” C:\\ Users \\ WORK \\ AppData \\ Local \\ Programs \\ Python \\ Python37-32 \\ lib \\ multiprocessing \\ pool.py“,第121行,在工作程序结果中=(True,func(* args,** kwds))文件“ C:\\ Users \\ IwI \\ AppData \\ Local \\ Programs \\ Python \\ Python37-32 \\ lib \\ multiprocessing \\ pool.py”,第44行在mapstar返回列表中(map(* args))文件“ C:\\ workspace \\ emsdk \\ emscripten \\ 1.38.14 \\ tools \\ shared.py”,行1363,在extract_archive_contents中声明为os.path.dirname(f)AssertionError。

Then I changed the way that I linked to Grassroot DICOM using 然后,我更改了使用以下方式链接到Grassroot DICOM的方式

-s RUNTIME_LINKED_LIBS=['gdcmcharls.a']
-s RUNTIME_LINKED_LIBS=['gdcmCommon.a']
-s RUNTIME_LINKED_LIBS=['gdcmDICT.a']
-s RUNTIME_LINKED_LIBS=['gdcmDSED.a']
.....

I get the error messages 我收到错误消息

wasm streaming compile failed: LinkError: Import 'env.getTempRet0' is invalid. wasm流式编译失败:LinkError:导入'env.getTempRet0'无效。 Expected type Function 预期类型功能

falling back to ArrayBuffer instantiation 回到ArrayBuffer实例化

and in the console shows this error 并在控制台中显示此错误

LinkError: Import 'env.getTempRet0' is invalid. LinkError:导入'env.getTempRet0'无效。 Expected type Function 预期类型功能

Just about my machine. 就是我的机器。 I use Windows10 64-bit and emcc (Emscripten gcc/clang-like replacement) 1.38.14 I serched online but it seems noone faces the same problem as me 我使用Windows10 64位和emcc(Emscripten gcc / clang-like替换)1.38.14我在网上服务,但似乎没有人遇到与我相同的问题

Update 更新

now I removed all dynamic link flag and the new problem arises 现在我删除了所有动态链接标志,并且出现了新问题

emcc -std=c++17 -O3 --no-heap-copy -s WASM=1  -s USE_WEBGL2=1 -s FULL_ES3=1 -s ALLOW_MEMORY_GROWTH=1 -o hello.html  -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall', 'cwrap']"        libgdcmcharls.bc libgdcmCommon.bc libgdcmDICT.bc libgdcmDSED.bc libgdcmexpat.bc libgdcmIOD.bc libgdcmjpeg12.bc libgdcmjpeg16.bc libgdcmjpeg8.bc libgdcmMEXD.bc libgdcmMSFF.bc libgdcmopenjp2.bc libgdcmzlib.bc libsocketxx.bc main.cpp  -o hello.js

multiprocessing.pool.RemoteTraceback: """ multiprocessing.pool.RemoteTraceback:“”“

Traceback (most recent call last): File "C:\\Users\\WORK\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\multiprocessing\\pool.py", line 121, in worker result = (True, func(*args, **kwds)) File "C:\\Users\\WORK\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\multiprocessing\\pool.py", line 44, in mapstar return list(map(*args)) File "C:\\workspace\\emsdk\\emscripten\\1.38.14\\tools\\shared.py", line 1364, in extract_archive_contents assert not os.path.dirname(f) AssertionError """ 追溯(最近一次呼叫最近):文件“ C:\\ Users \\ WORK \\ AppData \\ Local \\ Programs \\ Python \\ Python37-32 \\ lib \\ multiprocessing \\ pool.py”,第121行,工作结果中为(True,func( * args,** kwds))文件“ C:\\ Users \\ WORK \\ AppData \\ Local \\ Programs \\ Python \\ Python37-32 \\ lib \\ multiprocessing \\ pool.py”,mapstar返回列表中的第44行(map(* args ))文件“ C:\\ workspace \\ emsdk \\ emscripten \\ 1.38.14 \\ tools \\ shared.py”,第1364行,在extract_archive_contents中声明为os.path.dirname(f)AssertionError“”“

The above exception was the direct cause of the following exception: 上面的异常是以下异常的直接原因:

Traceback (most recent call last): File "C:\\workspace\\emsdk\\emscripten\\1.38.14\\emcc.py", line 3092, in sys.exit(run()) File "C:\\workspace\\emsdk\\emscripten\\1.38.14\\emcc.py", line 1699, in run final = shared.Building.link(linker_inputs, DEFAULT_FINAL, force_archive_contents=force_archive_contents, temp_files=misc_temp_files, just_calculate=just_calculate) File "C:\\workspace\\emsdk\\emscripten\\1.38.14\\tools\\shared.py", line 2011, in link Building.read_link_inputs([x for x in files if not x.startswith('-')]) File "C:\\workspace\\emsdk\\emscripten\\1.38.14\\tools\\shared.py", line 1852, in read_link_inputs object_names_in_archives = pool.map(extract_archive_contents, archive_names) File "C:\\Users\\WORK\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\multiprocessing\\pool.py", line 268, in map return self._map_async(func, iterable, mapstar, chunksize).get() File "C:\\Users\\WORK\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\multiprocessing\\pool.py", line 657, in get raise self._value AssertionError gmake: 追溯(最近一次通话):文件“ C:\\ workspace \\ emsdk \\ emscripten \\ 1.38.14 \\ emcc.py”,行309.,位于sys.exit(run())中文件“ C:\\ workspace \\ emsdk \\ emscripten \\ 1.38.14 \\ emcc.py“,第1699行,运行中=共享。 1.38.14 \\ tools \\ shared.py“,行2011,在链接Building.read_link_inputs中([x表示x,如果不是x.startswith('-'),则表示文件中的x]])文件” C:\\ workspace \\ emsdk \\ emscripten \\ 1.38 .14 \\ tools \\ shared.py“,行1852,在read_link_inputs中object_names_in_archives = pool.map(extract_archive_contents,archive_names)文件” C:\\ Users \\ WORK \\ AppData \\ Local \\ Programs \\ Python \\ Python37-32 \\ lib \\ multiprocessing \\ map中的第268行,pool.py”返回self._map_async(func,iterable,mapstar,chunksize).get()文件“ C:\\ Users \\ WORK \\ AppData \\ Local \\ Programs \\ Python \\ Python37-32 \\ lib \\ “ multiprocessing \\ pool.py”,行657,在get提高self._value AssertionError gmake中: *** [build] Error 1 *** [内部版本]错误1

It seems the problem that python cannot find the module inside the library files 似乎python无法在库文件中找到模块的问题

when I traced where the errors are 当我追踪错误在哪里

They are from Python function called 他们来自Python函数

# This function creates a temporary directory specified by the 'dir' field in
# the returned dictionary. Caller is responsible for cleaning up those files
# after done.
def extract_archive_contents(archive_file):


assert not os.path.dirname(f)  #This line causes the trouble

The correct way to use RUNTIME_LINKED_LIBS option should look like this: 使用RUNTIME_LINKED_LIBS选项的正确方法应如下所示:

-s RUNTIME_LINKED_LIBS=['gdcmcharls.a', 'gdcmCommon.a', 'gdcmDICT.a', 'gdcmDSED.a']

However, this may not be the solution you want. 但是,这可能不是您想要的解决方案。 Because you want statically linking the the libraries, not dynamically. 因为您要静态链接库,而不是动态链接。

The correct way to compile them together is just to include them as compile targets. 将它们一起编译的正确方法就是将它们作为编译目标。 The complete emcc option will look like this: 完整的emcc选项如下所示:

emcc --other-options-you-use \
     -s WASM=1 \
     gdcmcharls.a \
     gdcmCommon.a \
     gdcmDICT.a \
     gdcmDSED.a \
     your_other_source_files_1.c \
     your_other_source_files_2.cpp \
     -o output.js

Don't use -s SIDE_MODULE=1 flag. 不要使用-s SIDE_MODULE=1标志。 This is for dynamic linking. 这是用于动态链接。 -s EXPORT_ALL=1 is probably not you want neither. -s EXPORT_ALL=1可能既不是您也不想要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM