Emscripten compilation error: "'openssl/sha.h' file not found"

953 views Asked by At

I have a file called "speed.c" which I wish to use for a web program

This works:

 gcc speed.c -lcrypto -lssl

But this doesn't:

emcc speed.c -v -lcrypto -lssl -s EXPORTED_FUNCTIONS=_speed,_main -o speed.wasm

The function within speed.c is called "speed". On the website for Emscripten, it says that the compiler is just like any other so this one confuses me. Any help? Thanks!

1

There are 1 answers

0
cajomar On BEST ANSWER

Emscripten can't use you system's libraries. This is because they are binaries compiled for your own machine (probably 64-bit linux), while emcc compiles to WebAssembly/JavaScript. You can generally see what architecture a binary is targeting with file:

$ file `realpath /usr/lib/libssl.so`

Thus, you will need to first compile OpenSSL with emcc. I haven't done this myself, but I believe it's possible. You could check out this github issue. Once you've done that you should have two files name libssl.a and libcrypto.a. Then you can compile your own project like this:

$ SSL=/path/to/openssl
$ emcc speed.c $SSL/libssl.a $SSL/libcrypto.a -I $SSL/include/  # etc.

Take a look at the project building page if you haven't yet.