当我尝试将我的wasm代码与静态库,Grassroot DICOM库链接时出错。
首先,我使用带有外部工具链的cmake和从/1.38.14/cmake/Modules/Platform中找到的cmake编译Grassroot DICOM
将Windows 10与Visual Studio 2017和Windows 8.1 SDK一起使用。
编译完成后。我有静态链接文件
libgdcmcharls.a
libgdcmCommon.a
libgdcmDICT.a
libgdcmDSED.a
....
然后我使用flag将这些文件链接到我的代码
-L<PATH-to-library>
-lgdcmcharls -lgdcmCommon -lgdcmDICT -lgdcmDSED ...
还使用:
-s WASM=1 -s SIDE_MODULE=1 -s EXPORT_ALL=1
这些库可以链接,也无法编译。错误是
multiprocessing.pool.RemoteTraceback:“”“Traceback(最近一次调用最后一次):文件”C:\ Users \ WORK \ AppData \ Local \ Programs \ Python \ Python37-32 \ lib \ multiprocessing \ pool.py“,第121行, in worker result =(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。
然后我改变了我使用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']
.....
我收到错误消息
wasm流编译失败:LinkError:导入'env.getTempRet0'无效。预期类型功能
回到ArrayBuffer实例化
并在控制台中显示此错误
LinkError:导入'env.getTempRet0'无效。预期类型功能
关于我的机器。我使用Windows10 64位和emcc(Emscripten gcc / clang-like replacement)1.38.14我在网上发布但似乎没有人像我一样面临同样的问题
现在我删除了所有动态链接标志,出现了新问题
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:“”“
回溯(最近一次调用最后一次):文件“C:\ Users \ WORK \ AppData \ Local \ Programs \ Python \ Python37-32 \ lib \ multiprocessing \ pool.py”,第121行,在worker result =(True,func( * args,** kwds))文件“C:\ Users \ WORK \ AppData \ Local \ Programs \ Python \ Python37-32 \ lib \ multiprocessing \ pool.py”,第44行,在mapstar返回列表中(map(* args) ))文件“C:\ workspace \ emsdk \ emscripten \ 1.38.14 \ tools \ shared.py”,第1364行,在extract_archive_contents中断言不是os.path.dirname(f)AssertionError“”“
上述异常是以下异常的直接原因:
回溯(最近一次调用最后一次):文件“C:\ workspace \ emsdk \ emscripten \ 1.38.14 \ emcc.py”,第3092行,在sys.exit(run())文件“C:\ workspace \ emsdk \ emscripten \ 1.38.14 \ emcc.py“,第1699行,在run final = shared.Building.link(linker_inputs,DEFAULT_FINAL,force_archive_contents = force_archive_contents,temp_files = misc_temp_files,just_calculate = just_calculate)文件”C:\ workspace \ emsdk \ emscripten \ 1.38.14 \ tools \ shared.py“,第2011行,链接Building.read_link_inputs(如果不是x.startswith(' - '),文件中的x为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 \ pool.py“,第268行,在map中返回self._map_async(func,iterable,mapstar,chunksize).get()文件”C:\ Users \ WORK \ AppData \ Local \ Programs \ Python \ Python37-32 \ lib \ multiprocessing \ pool.py“,第657行,in get raise self._value AssertionError gmake: *** [build]错误1
似乎python无法在库文件中找到模块的问题
当我追踪错误的地方时
它们来自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
使用RUNTIME_LINKED_LIBS
选项的正确方法应如下所示:
-s RUNTIME_LINKED_LIBS=['gdcmcharls.a', 'gdcmCommon.a', 'gdcmDICT.a', 'gdcmDSED.a']
但是,这可能不是您想要的解决方案。因为您希望静态链接库,而不是动态链接。
将它们编译在一起的正确方法就是将它们包含在编译目标中。完整的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
不要使用-s SIDE_MODULE=1
标志。这是用于动态链接。 -s EXPORT_ALL=1
可能不是你想要的。