我正在尝试将 librdkafka 编译成 wasm 二进制文件。我执行了以下命令,但在第二行,wasm-ld 没有找到 pthread 相关符号。
emcmake cmake -H. -B_cmake_build
cmake --build _cmake_build
[ 34%] Linking C executable producer.js
wasm-ld: error: ../src/librdkafka.a(rdkafka.c.o): undefined symbol: pthread_kill
wasm-ld: error: ../src/librdkafka.a(rdkafka.c.o): undefined symbol: pthread_kill
我尝试了多种方法将
-pthread
标志注入链接器,但遇到了同样的错误。以下是我尝试过的几个命令
emcmake cmake -H. -B_cmake_build -DCMAKE_SHARED_LINKER_FLAGS="-lpthread"
emcmake cmake -H. -B_cmake_build -DCFLAGS="-lpthread"
LDFLAGS="-pthread" cmake --build _cmake_build
经过一番研究,我发现它是
EMCC_CFLAGS
。
EMCC_CFLAGS="-pthread" cmake --build _cmake_build
https://emscripten.org/docs/tools_reference/emcc.html#environment-variables