我想编译一个从C到WebAssembly的程序。程序应该使用一个数字,计算素数,直到给定的数字,然后返回经过的时间(以微秒为单位)。在编译过程中,我使用了Emscripten,并得到了这样一个错误:
"C:\Users\Pawel\Desktop\Wasm\main.c:20:1: error:函数'calcPrimes‘的隐式声明在C99中无效
[-Werror,-Wimplicit-function-declaration]calcPrimes(数);
^
1产生错误。
错误:'C:/Users/Pawel/Desktop/emsdk/emsdk/upstream/bin\clang.exe -target wasm32 32-unknown emscripten -D__EMSCRIPTEN_major__=1 -D__EMSCRIPTEN_minor__=39 -D__EMSCRIPTEN_tiny__=15 -D_LIBCPP_ABI_VERSION=2 -Dunix -D__unix -D__unix__ -Werror=隐式函数声明-Xclang -nostdsysteminc -Xclang -isystemC:\Users\Pawel\Desktop\emsdk\emsdk\upstream\emscripten\system\include\复配-isystemC:\Users\Pawel\Desktop\emsdk\emsdk\upstream\emscripten\system\include -isystemC:\Users\Pawel\Desktop\emsdk\emsdk\upstream\emscripten\system\include\libc -Xclang -isystemC:\Users\Pawel\Desktop\emsdk\emsdk\upstream\emscripten\system\lib\libc\musl\arch\emscripten -Xclang -isystemC:\Users\Pawel\Desktop\emsdk\emsdk\upstream\emscripten\system\local\include -Xclang -isystemC:\Users\Pawel.emscripten_cache\wasm\包括-isystemC:\Users\Pawel\Desktop\emsdk\emsdk\upstream\emscripten\system\include\SDL -fignore-异常C:\ -DEMSCRIPTEN \Pawel\Desktop\Wasm\main.c -Xclang -c -o -mllvm -组合器-全局-别名-分析=假-mllvm -启用-emscripten-sjlj -mllvm -禁用-lsr‘失败(1)“
提前感谢您的帮助!
我的代码:
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <emscripten.h>
EMSCRIPTEN_KEEPALIVE
long getDuration(int number){
struct timespec ts;
struct timespec {
time_t tv_sec;
long tv_nsec;
};
timespec_get(&ts, TIME_UTC);
long startsc = ts.tv_sec;
long startns = ts.tv_nsec;
calcPrimes(number);
timespec_get(&ts, TIME_UTC);
long endsc = ts.tv_sec;
long endns = ts.tv_nsec;
long resus = (endsc - startsc) * 1000000 + (endns/1000) - (startns/1000);
return resus;
}
int isPrime(int num) {
int i;
if(num == 2) return 1;
if(num % 2 == 0) return 0;
int sq = (int) sqrt(num) + 1;
for(i = 3; i < sq; i = i + 2) if(num % i == 0) return 0;
return 1;
}
int calcPrimes(int n) {
int i, count = 0;
for(i = 2; i <= n; i++) if(isPrime(i)) count++;
return count;
}发布于 2020-05-08 02:17:25
您缺少了calcPrimes的前向声明。您要么需要添加一个,要么在文件中将getDuration移到calcPrimes下面。
https://stackoverflow.com/questions/61665192
复制相似问题