1

我一直在通过尝试编译一些使用“sys/shm.h”的基本 wasm 示例来探索 emscripten

这是我要编译的代码:

#include <stdio.h>
#include <sys/shm.h> 

int main(int argc, char *argv[]) {
    key_t key = ftok("shmfile",65); 
    int shmid = shmget(key,1024,0666|IPC_CREAT); 

    char *str = (char*) shmat(shmid,(void*)0,0); 
    sprintf(str, "balhhh");

    printf("Data in memory: %s\n",str); 

    shmdt(str); 
    return 0; 
}

这是我的编译输出:

➜  wasm emcc --version
emcc (Emscripten gcc/clang-like replacement) 1.39.8 (commit 1458145cf4f3db0fb548343e6acab267eef8e4ef)
Copyright (C) 2014 the Emscripten authors (see AUTHORS.txt)
This is free and open source software under the MIT license.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


➜  wasm emcc -o shared.html shared.c -s WASM=1 -s USE_PTHREADS=1                        
error: undefined symbol: ftok
warning: Link with `-s LLD_REPORT_UNDEFINED` to get more information on undefined symbols
warning: To disable errors for undefined symbols use `-s ERROR_ON_UNDEFINED_SYMBOLS=0`
error: undefined symbol: shmat
error: undefined symbol: shmdt
error: undefined symbol: shmget
Error: Aborting compilation due to previous errors
shared:ERROR: '/home/wave/Downloads/emsdk/node/12.9.1_64bit/bin/node /home/wave/Downloads/emsdk/upstream/emscripten/src/compiler.js /tmp/tmpiWE3Ei.txt' failed (1)


➜  wasm emcc -o shared.html shared.c -s WASM=1 -s USE_PTHREADS=1 -s LLD_REPORT_UNDEFINED
wasm-ld: error: /tmp/emscripten_temp_bNjvle/shared_0.o: undefined symbol: ftok
wasm-ld: error: /tmp/emscripten_temp_bNjvle/shared_0.o: undefined symbol: shmget
wasm-ld: error: /tmp/emscripten_temp_bNjvle/shared_0.o: undefined symbol: shmat
wasm-ld: error: /tmp/emscripten_temp_bNjvle/shared_0.o: undefined symbol: shmdt
wasm-ld: error: /home/wave/.emscripten_cache/wasm-obj/libc-mt.a(emscripten_pthread.c.o): undefined symbol: initPthreadsJS
shared:ERROR: '/home/wave/Downloads/emsdk/upstream/bin/wasm-ld -o /tmp/emscripten_temp_bNjvle/shared.wasm --lto-O0 /tmp/emscripten_temp_bNjvle/shared_0.o -L/home/wave/Downloads/emsdk/upstream/emscripten/system/local/lib -L/home/wave/Downloads/emsdk/upstream/emscripten/system/lib -L/home/wave/.emscripten_cache/wasm-obj /home/wave/.emscripten_cache/wasm-obj/libc-mt.a /home/wave/.emscripten_cache/wasm-obj/libcompiler_rt.a /home/wave/.emscripten_cache/wasm-obj/libc-wasm.a /home/wave/.emscripten_cache/wasm-obj/libdlmalloc-mt.a /home/wave/.emscripten_cache/wasm-obj/libpthread-mt.a /home/wave/.emscripten_cache/wasm-obj/libc_rt_wasm.a /home/wave/.emscripten_cache/wasm-obj/libsockets-mt.a --allow-undefined-file=/tmp/tmp5_bZ9l.undefined --import-memory --import-table --shared-memory -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --strip-debug --export __wasm_call_ctors --export __data_end --export main --export __errno_location --export emscripten_get_global_libc --export __pthread_tsd_run_dtors --export __emscripten_pthread_data_constructor -z stack-size=5242880 --initial-memory=16777216 --no-entry --max-memory=16777216 --global-base=1024' failed (1)

我猜 emscripten 中有共享内存支持,但我无法wasm-ld正确链接它。任何人都可以帮忙吗?

谢谢,盖尔

4

1 回答 1

0

Emscripten 不支持 SysV 共享内存(sys/shm.h 中的函数)。

于 2020-02-18T17:14:58.603 回答