Compile with Zlib

32 views
Skip to first unread message

Davide Mercanti

unread,
Oct 31, 2024, 9:27:13 AM10/31/24
to emscripten-discuss


I don't understand how I can set up a project to use zlib (USE_ZLIB=1) with MSVC 2019 and cmake.

Is am example project available?

These are my outputs

D:\MERCHANTS\em\emsdk\upstream\emscripten\em++.bat -ID:/MERCHANTS/em/emsdk/upstream/emscripten/system/include -g -MD -MT CMakeProject1/CMakeFiles/CMakeProject1.dir/CMakeProject1.cpp.o -MF CMakeProject1\CMakeFiles\CMakeProject1.dir\CMakeProject1.cpp.o.d -o CMakeProject1/CMakeFiles/CMakeProject1.dir/CMakeProject1.cpp.o -c ../../../CMakeProject1/CMakeProject1.cpp
 [2/2] cmd.exe /C "cd . && D:\MERCHANTS\em\emsdk\upstream\emscripten\em++.bat -g --bind -s USE_ZLIB=1 -s EXPORT_ALL=1 -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s FORCE_FILESYSTEM=1 -s EXPORTED_RUNTIME_METHODS=['ccall','cwrap'] -s EXPORTED_FUNCTIONS=['_print_file','_testdouble_array','_malloc','_free','_unzip_file'] CMakeProject1/CMakeFiles/CMakeProject1.dir/CMakeProject1.cpp.o -o CMakeProject1\MyFirstWASM.html && cd .'
 FAILED: CMakeProject1/MyFirstWASM.html
 cmd.exe /C "cd . && D:\MERCHANTS\em\emsdk\upstream\emscripten\em++.bat -g --bind -s USE_ZLIB=1 -s EXPORT_ALL=1 -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s FORCE_FILESYSTEM=1 -s EXPORTED_RUNTIME_METHODS=['ccall','cwrap'] -s EXPORTED_FUNCTIONS=['_print_file','_testdouble_array','_malloc','_free','_unzip_file'] CMakeProject1/CMakeFiles/CMakeProject1.dir/CMakeProject1.cpp.o -o CMakeProject1\MyFirstWASM.html && cd ."
D:\MERCHANTS\em\sources\CMakeProject1\out\build\x64-Debug\CMakeProject1\wasm-ld : error : CMakeProject1/CMakeFiles/CMakeProject1.dir/CMakeProject1.cpp.o: undefined symbol: zip_open
D:\MERCHANTS\em\sources\CMakeProject1\out\build\x64-Debug\CMakeProject1\wasm-ld : error : CMakeProject1/CMakeFiles/CMakeProject1.dir/CMakeProject1.cpp.o: undefined symbol: zip_get_num_entries
D:\MERCHANTS\em\sources\CMakeProject1\out\build\x64-Debug\CMakeProject1\wasm-ld : error : CMakeProject1/CMakeFiles/CMakeProject1.dir/CMakeProject1.cpp.o: undefined symbol: zip_stat_index
D:\MERCHANTS\em\sources\CMakeProject1\out\build\x64-Debug\CMakeProject1\wasm-ld : error : CMakeProject1/CMakeFiles/CMakeProject1.dir/CMakeProject1.cpp.o: undefined symbol: zip_close



Sam Clegg

unread,
Oct 31, 2024, 9:29:24 AM10/31/24
to emscripte...@googlegroups.com
Those undefined symbols looks like they come from libzip, rather than zlib: https://libzip.org/documentation/zip_get_num_entries.html

That means you will likely need to compile libzip and link it into your project rather than using `-sUSE_ZLIB`.

cheers,
sam
 



--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/emscripten-discuss/6165639e-23cc-4f81-a2a0-adb89357599bn%40googlegroups.com.

Mercp

unread,
Oct 31, 2024, 2:44:53 PM10/31/24
to emscripte...@googlegroups.com

Thank you.  So zlib can't access zip file entries?  Has libzip never been linked?


You received this message because you are subscribed to a topic in the Google Groups "emscripten-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/emscripten-discuss/foCw8MVFchE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to emscripten-disc...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/emscripten-discuss/CAL_va28ycVsbrw0%2Bf5-GEdHp2rc3mFCkhnVO1%3DHaYBCe1SHWeQ%40mail.gmail.com.

Brooke Vibber

unread,
Oct 31, 2024, 4:25:35 PM10/31/24
to emscripte...@googlegroups.com
On Thu, Oct 31, 2024 at 11:44 AM Mercp <d.mer...@gmail.com> wrote:

Thank you.  So zlib can't access zip file entries?  Has libzip never been linked?

zlib handles gzip files: https://zlib.net/
libzip handles zip files: https://libzip.org/

You can probably compile libzip fairly straightforwardly, then link it into your project just as you would any other library.

-- brooke

Mercp

unread,
Nov 2, 2024, 5:38:22 PM11/2/24
to emscripte...@googlegroups.com
Ok. I've compiled libzip.
I can read entries names but how can I pass buffer to Javascript for this C function?

int zipG(const char* zip_file_name, char* ZipBuf2) {
        int v1=zip_entry_opencasesensitive(gloablZip, zip_file_name);
        cout << v1 << endl;
        zip_entry_read(gloablZip, (void**)&ZipBuf2, &ZipBuf_size);

            cout << ZipBuf_size << endl;
        return 0;
    }

in JS:


var myBuffer= cArray8(32000)
Module.ccall('zipG', 'number', ['string','number'], ['model.dat',myBuffer.offset]);



function cArray8(size) {
    var offset = Module._malloc(size * 1);
    Module.HEAP8.set(new Uint8Array(size), offset / 1);
    return {
"data": Module.HEAP8.subarray(offset / 1, offset / 1 + size),
"offset": offset
}
};

--
You received this message because you are subscribed to a topic in the Google Groups "emscripten-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/emscripten-discuss/foCw8MVFchE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to emscripten-disc...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages