emscripten-core / emscripten-core/emscripten

How can I link a .so file that is a shared library?

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

Description

How can I link a .so file that is a shared library?

Hello.
1. I want to convert tester.c to tester.js file.
I need to link libMagicCrypto.so shared library to tester.c.

2. I entered the following command.
`$ emcc tester.c -lMagicCrypto -L/home/jyh7a/webassembly -I/home/jyh7a/webassembly -ldl -o tester.js`

But wasm-ld throws an unknown file type error and
emcc error also occurs. (It is attached below.)

2-1.
`wasm-ld: error: unknown file type: /home/jyh7a/webassembly/libMagicCrypto.so`

2-2.
```
emcc: error: '/home/jyh7a/emsdk/upstream/bin/wasm-ld -o tester.wasm /tmp/emscripten_temp_rtzaszvu/tester_0.o /home/jyh7a/webassembly/libMagicCrypto.so -L/home/jyh7a/webassembly -L/home/jyh7a/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten -lGL -lal -lhtml5 -lstubs-debug -lnoexit -lc-debug -ldlmalloc -lcompiler_rt -lc++-noexcept -lc++ abi-noexcept -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --import-undefined --strip-debug --export-if-defined=main --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__stdio_exit --export=emscripten_stack_get_end --export=emscripten_stack_get_free --export=emscripten_stack_get_base --export=emscripten_stack_init -- =stackSave --export=stackRestore --export=stackAlloc --export=__wasm_call_ctors --export=__errno_location --export-table -z stack-size=5242880 --initial-memory=16777216 --no-entry --max- memory=16777216 --global-base=1024' failed (returned 1)
```

3. This is my folder structure. (All files in webassembly were delivered from other companies.)
```
webassembly
├── libMagicCrypto.so
├── libMagicCrypto.so.lic
├── mcapi.h
├── mcapi_error.h
├── mcapi_type.h
└── tester.c
```

4. Version of emscripten/emsdk:
```
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.7 (48a16209b1a0de5efd8112ce6430415730008d18)
clang version 15.0.0 (https://github.com/llvm/llvm-project fbce4a78035c32792b0a13cf1f169048b822c06b)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /home/jyh7a/emsdk/upstream/bi
```

5.
5-1. Is it possible to dynamically link a shared library called .so ?
5-2. I wonder what is the cause of that error and how to fix it.
5-3. Please let me know if you need more information to solve the problem.

Thank you for your interest.

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.