emscripten-core / emsdk

Emscripten SDK
http://emscripten.org
Other
3k stars 683 forks source link

em++ hangs when run #1365

Closed Matt-DESTROYER closed 6 months ago

Matt-DESTROYER commented 6 months ago

Trying to build a simple C++ file as part of a mini experiment/project. I might be doing something completely wrong, I'm not sure, but essentially when I try to compile the below C++ file with the below command, it just hangs everytime (I keep waiting around ten minutes and getting nothing, I assume it probably shouldn't take that long regardless). Compute.cpp

#ifndef __int64
#define __int64 long long
#endif

extern "C" {
    __int64  piBBP(__int64 offset, __int64 digits);
}

long double decMod(long double x, long double y) {
    while (x >= y) {
        x -= y;
    }
    return x;
}

__int64 modPow(__int64 b, __int64 e, __int64 m) {
    b = b % m;
    __int64 y = 1;
    while (e > 0) {
        if (e & 1) {
            y = (y * b) % m;
        }
        b = (b * b) % m;
        e >>= 1;
    }
    return y;
}

long double mod(long double x, long double n) {
    x = decMod(x, n);
    return x < 0 ? x + n : x;
}

long double S(__int64 j, __int64 n) {
    long double left = 0;
    for (__int64 k = 0; k <= n; k++) {
        __int64 r = 8 * k + j;
        left = mod(left + (long double)modPow(16, n - k, r) / r, 1);
    }

    long double right = 0;
    for (__int64 k = n + 1; ; k++) {
        long double rnew = right + pow(16, (n - k)) / (8 * k + j);
        if (right == rnew) {
            break;
        }
        right = rnew;
    }
    return left + right;
}

__int64 pow(__int64 x, __int64 y) {
    __int64 res = 1;
    for (;;) {
        if (y & 1) {
            res *= x;
        }
        y >>= 1;
        if (!y) {
            break;
        }
        x *= x;
    }
    return res;
}

__int64  piBBP(__int64 offset, __int64 digits) {
    return (__int64)(pow(16, digits) * mod(4 * S(1, offset) - 2 * S(4, offset)- S(5, offset) - S(6, offset), 1));
}

(I was previously using the cmath header, but even without this it still fails.) CMD

em++ Compute.cpp -O2 -s EXPORTED_FUNCTIONS=_piBPP --no-entry -o Compute.wasm

Eventually, on one attempt I got this warning:

cache:WARNING: Accessing the Emscripten cache at "C:\Program Files\emsdk\upstream\emscripten\cache" (for "sanity") is taking a long time, another process should be writing to it. If there are none and you suspect this process has deadlocked, try deleting the lock file "C:\Program Files\emsdk\upstream\emscripten\cache\cache.lock" and try again. If this occurs deterministically, consider filing a bug.

A quick look in the folder C:\Program Files\emsdk\upstream\emscripten\cache\ shows there is no such file as cache.lock...

It did seem to work previously and my C++ file would compile (although at the time I hadn't figured out how to configure it properly so it basically output an essentially empty WASM file), but I have not been able to get this working since. I even tried completely deleting and reinstalling emsdk and that didn't seem to work.

Note: This is on x64 Windows 11.

kripken commented 6 months ago

Possibly this is a windows issue of some kind, but the first thing I would try is manually delete that cache/ directory entirely. Emscripten will recreate it and perhaps that will fix the issue for you.

Matt-DESTROYER commented 6 months ago

Thanks, that seemed to work!