emscripten-core / emscripten-core/emscripten

General questions regarding OpenSSL linking

Open
#19,597 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

Im struggeling with compiling OpenSSL for emscripten. Also there are a few things that i dont really understand.

I tried to compile OpenSSL 1.1.1u on ubuntu.
The only special flag added to the config is the no-tests, since some tests had duplicate symbols for me, so i just didnt compile them at all.
`emconfigure ./Configure no-tests linux-generic64 --prefix=$EMSCRIPTEN/system`

Next i executed this command to change the cross compilation directory? Actually i have no idea why and i cant tell anymore where i did get this from, but without this the compilation fails:
`sed -i 's|^CROSS_COMPILE.*$|CROSS_COMPILE=|g' Makefile`

Then i modified the Makefile manually to compile OpenSSL with emscripten pthreads because my other code uses pthreads and also to compile OpenSSL as a sidemodule. I think this is necessary so that dlopen() works which is needed by OpenSSL, but please correct me if im wrong. (Im not sure if there is a way to compile OpenSSL so that it does not need dlopen() to work)
`CFLAGS=-O3 -Wall -s USE_PTHREADS -sSIDE_MODULE`

Finally i just start the compilation:
`emmake make`

I put the generated *.a files (libcrypto.a and libssl.a) into the root directory of my project.

The project itself im compiling with the following flags:
`em++ -sMAIN_MODULE -lembind -sASSERTIONS -std=c++17 -O0 -lwebsocket.js -pthread -sPROXY_TO_PTHREAD -sASYNCIFY -s ALLOW_MEMORY_GROWTH=1 ../Test.cpp -o out.html --shell-file index.html -I ../Libs/openssl_emscripten/include libcrypto.a libssl.a --bind`

I think the important parts here are the pthread linking and that libcrypto and libssl are listed here so that they can get linked. Also this is compiled as the MAIN_MODULE so that it can load the SIDE_MODULEs such as OpenSSL i suppose?
This produces this output:
```em++: warning: EXPORTED_FUNCTIONS is not valid with LINKABLE set (normally due to SIDE_MODULE=1/MAIN_MODULE=1) since all functions are exported this mode. To export only a subset use SIDE_MODULE=2/MAIN_MODULE=2 [-Wunused-command-line-argument]
em++: warning: -sMAIN_MODULE + pthreads is experimental [-Wexperimental]
em++: warning: -pthread + ALLOW_MEMORY_GROWTH may run non-wasm code slowly, see https://github.com/WebAssembly/design/issues/1271 [-Wpthreads-mem-growth]
error: undefined symbol: _Z13base64_decodeRKNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEE (referenced by top-level compiled C/C++ code)
warning: To disable errors for undefined symbols use `-sERROR_ON_UNDEFINED_SYMBOLS=0`
warning: __Z13base64_decodeRKNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEE may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _Z13base64_encodePKhj (referenced by top-level compiled C/C++ code)
warning: __Z13base64_encodePKhj may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
Error: Aborting compilation due to previous errors
em++: error: '/node/15.14.0_64bit/bin/node.exe E:\DATA\Libs\emscripten\emsdk-main\upstream\emscripten\src\compiler.js \AppData\Local\Temp\tmpzc6xe8_z.json' failed (returned 1)
```

I really dont understand this error message. It seems that some base64 encoding function is not present?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.