emscripten-core / emsdk

Emscripten SDK
http://emscripten.org
Other
2.92k stars 662 forks source link

`emcc: error: undefined exported symbol` for a static function #1320

Closed vault-thirteen closed 7 months ago

vault-thirteen commented 7 months ago

I am trying to build a library for WASM and I set the list of functions to export. One function raises an error and this function is a static one.

emcmake cmake . -B "_BUILD_" -G "MinGW Makefiles"
emmake cmake --build _BUILD_
cd _BUILD_
emcc libargon2.a -o argon2.wasm --no-entry -s EXPORTED_FUNCTIONS=["_argon2_compare","_argon2_ctx","_argon2_encodedlen","_argon2_error_message","_argon2_hash","_argon2_type2string","_argon2_verify","_argon2_verify_ctx","_argon2d_ctx","_argon2d_hash_encoded","_argon2d_hash_raw","_argon2d_verify","_argon2d_verify_ctx","_argon2i_ctx","_argon2i_hash_encoded","_argon2i_hash_raw","_argon2i_verify","_argon2i_verify_ctx","_argon2id_ctx","_argon2id_hash_encoded","_argon2id_hash_raw","_argon2id_verify","_argon2id_verify_ctx"]

Output:

cache:INFO: generating system asset: symbol_lists/c159062c4c7cca655ffe94279476b11a0cfc7d1c.json... (this will be cached in "D:\Temp\1\emsdk\upstream\emscripten\cache\symbol_lists\c159062c4c7cca655ffe94279476b11a0cfc7d1c.json" for subsequent builds)
cache:INFO:  - ok
emcc: error: undefined exported symbol: "_argon2_compare" [-Wundefined] [-Werror]

What is wrong with it ? Does WASM support static functions ? https://github.com/vault-thirteen/argon2/blob/main/src/argon2.c#L239

P. S.

Without this function there are no errors, so this one is the reason.

Thank you.

sbc100 commented 7 months ago

_argon2_compare is marked as a static function with in argon2.c which means it is only available within that source file, and not public symbol than can be exported.

vault-thirteen commented 7 months ago

Thank you. I forgot that static in C is not the same as in C++. My bad. Thank you.