考虑以下示例(来自get_nprocs手册页):

#include <stdlib.h>
#include <stdio.h>
#include <sys/sysinfo.h>

int main(int argc, char *argv[])
{
    printf("This system has %d processors configured and "
            "%d processors available.\n",
            get_nprocs_conf(), get_nprocs());
    exit(EXIT_SUCCESS);
}

它使用g++编译并运行。但是,使用emscripten em ++编译时,出现以下错误:
em++ nproc.cpp -o nproc.html
error: undefined symbol: get_nprocs
warning: To disable errors for undefined symbols use `-s ERROR_ON_UNDEFINED_SYMBOLS=0`
error: undefined symbol: get_nprocs_conf
Error: Aborting compilation due to previous errors
shared:ERROR: '/home/hiisi/workspace/emsdk/node/8.9.1_64bit/bin/node /home/hiisi/workspace/emsdk/fastcomp/emscripten/src/compiler.js /tmp/tmp2SSe0B.txt /home/hiisi/workspace/emsdk/fastcomp/emscripten/src/library_pthread_stub.js' failed (1)

如何在Webassembly中使用get_nprocs()

最佳答案

似乎sysinfo仍未实现:https://github.com/emscripten-core/emscripten/issues/8038虽然可以从JS检索到内核数:Get number of CPU cores in JavaScript?

关于c++ - webassembly和get_nprocs(),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57191745/

10-11 18:28