emscripten-core / emscripten-core/emscripten
"No thread API" error on C++ compile (macOS)
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
Trying to create simple .wasm file for use in Javascript (similar to something I've done with C based emcc project) and getting the following error when I attempt to compile.
Any thoughts much appreciated!
**Trace**
```
"/usr/local/opt/emscripten/libexec/llvm/bin/clang++" -DEMSCRIPTEN -fignore-exceptions -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -Xclang -isystem/usr/local/Cellar/emscripten/2.0.12/libexec/system/include/SDL -target wasm32-unknown-emscripten -D__EMSCRIPTEN_major__=2 -D__EMSCRIPTEN_minor__=0 -D__EMSCRIPTEN_tiny__=12 -D_LIBCPP_ABI_VERSION=2 -Dunix -D__unix -D__unix__ -Werror=implicit-function-declaration --sysroot=/usr/local/Cellar/emscripten/2.0.12/libexec/system -Xclang -isystem/usr/local/Cellar/emscripten/2.0.12/libexec/cache/include -Xclang -iwithsysroot/include/libcxx -Xclang -iwithsysroot/lib/libcxxabi/include -Xclang -iwithsysroot/include/compat -Xclang -iwithsysroot/include/libc -Xclang -iwithsysroot/lib/libc/musl/arch/emscripten -Xclang -iwithsysroot/local/include -Xclang -iwithsysroot/include/SSE -Xclang -iwithsysroot/include/neon -Xclang -iwithsysroot/lib/compiler-rt/include -Xclang -iwithsysroot/lib/libunwind/include --target=wasm32-unknown-unknown-wasm --optimize=3 -v ./lttb.cpp -c -o /var/folders/xj/yxtdtt1n42l5m_6pxn_1yspw0000gn/T/emscripten_temp_ukq5xqc_/lttb_0.o
clang version 12.0.0 (https://github.com/llvm/llvm-project.git 52e240a0721e4120a7143f6f5bab4760d28d48e8)
Target: wasm32-unknown-unknown-wasm
Thread model: posix
InstalledDir: /usr/local/opt/emscripten/libexec/llvm/bin
(in-process)
"/usr/local/Cellar/emscripten/2.0.12/libexec/llvm/bin/clang-12" -cc1 -triple wasm32-unknown-unknown-wasm -emit-obj --mrelax-relocations -disable-free -disable-llvm-verifier -discard-value-names -main-file-name lttb.cpp -mrelocation-model static -mframe-pointer=none -fno-rounding-math -mconstructor-aliases -target-cpu generic -fvisibility hidden -debugger-tuning=gdb -target-linker-version 609.8 -v -resource-dir /usr/local/Cellar/emscripten/2.0.12/libexec/llvm/lib/clang/12.0.0 -D EMSCRIPTEN -D __EMSCRIPTEN_major__=2 -D __EMSCRIPTEN_minor__=0 -D __EMSCRIPTEN_tiny__=12 -D _LIBCPP_ABI_VERSION=2 -D unix -D __unix -D __unix__ -isysroot /usr/local/Cellar/emscripten/2.0.12/libexec/system -internal-isystem /usr/local/Cellar/emscripten/2.0.12/libexec/system/include/c++/v1 -internal-isystem /usr/local/Cellar/emscripten/2.0.12/libexec/llvm/lib/clang/12.0.0/include -internal-isystem /usr/local/Cellar/emscripten/2.0.12/libexec/system/include -O3 -Werror=implicit-function-declaration -fdeprecated-macro -fdebug-compilation-dir /Users/josh/Code/js/idv/app/wasm/cpp -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fignore-exceptions -fexceptions -fcolor-diagnostics -vectorize-loops -vectorize-slp -isystem/usr/local/Cellar/emscripten/2.0.12/libexec/system/include/SDL -isystem/usr/local/Cellar/emscripten/2.0.12/libexec/cache/include -iwithsysroot/include/libcxx -iwithsysroot/lib/libcxxabi/include -iwithsysroot/include/compat -iwithsysroot/include/libc -iwithsysroot/lib/libc/musl/arch/emscripten -iwithsysroot/local/include -iwithsysroot/include/SSE -iwithsysroot/include/neon -iwithsysroot/lib/compiler-rt/include -iwithsysroot/lib/libunwind/include -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -o /var/folders/xj/yxtdtt1n42l5m_6pxn_1yspw0000gn/T/emscripten_temp_ukq5xqc_/lttb_0.o -x c++ ./lttb.cpp
clang -cc1 version 12.0.0 based upon LLVM 12.0.0git default target x86_64-apple-darwin19.5.0
ignoring nonexistent directory "/usr/local/Cellar/emscripten/2.0.12/libexec/cache/include"
ignoring nonexistent directory "/usr/local/Cellar/emscripten/2.0.12/libexec/system/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/Cellar/emscripten/2.0.12/libexec/system/include/SDL
/usr/local/Cellar/emscripten/2.0.12/libexec/system/include/libcxx
/usr/local/Cellar/emscripten/2.0.12/libexec/system/lib/libcxxabi/include
/usr/local/Cellar/emscripten/2.0.12/libexec/system/include/compat
/usr/local/Cellar/emscripten/2.0.12/libexec/system/include/libc
/usr/local/Cellar/emscripten/2.0.12/libexec/system/lib/libc/musl/arch/emscripten
/usr/local/Cellar/emscripten/2.0.12/libexec/system/local/include
/usr/local/Cellar/emscripten/2.0.12/libexec/system/include/SSE
/usr/local/Cellar/emscripten/2.0.12/libexec/system/include/neon
/usr/local/Cellar/emscripten/2.0.12/libexec/system/lib/compiler-rt/include
/usr/local/Cellar/emscripten/2.0.12/libexec/system/lib/libunwind/include
/usr/local/Cellar/emscripten/2.0.12/libexec/llvm/lib/clang/12.0.0/include
/usr/local/Cellar/emscripten/2.0.12/libexec/system/include
End of search list.
In file included from ./lttb.cpp:3:
In file included from /usr/local/Cellar/emscripten/2.0.12/libexec/system/include/emscripten/bind.h:14:
In file included from /usr/local/Cellar/emscripten/2.0.12/libexec/system/include/libcxx/stddef.h:39:
/usr/local/Cellar/emscripten/2.0.12/libexec/system/include/libcxx/__config:1134:6: error: "No thread API"
# error "No thread API"
^
1 error generated.
emcc: error: '/usr/local/opt/emscripten/libexec/llvm/bin/clang++ -DEMSCRIPTEN -fignore-exceptions -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -Xclang -isystem/usr/local/Cellar/emscripten/2.0.12/libexec/system/include/SDL -target wasm32-unknown-emscripten -D__EMSCRIPTEN_major__=2 -D__EMSCRIPTEN_minor__=0 -D__EMSCRIPTEN_tiny__=12 -D_LIBCPP_ABI_VERSION=2 -Dunix -D__unix -D__unix__ -Werror=implicit-function-declaration --sysroot=/usr/local/Cellar/emscripten/2.0.12/libexec/system -Xclang -isystem/usr/local/Cellar/emscripten/2.0.12/libexec/cache/include -Xclang -iwithsysroot/include/libcxx -Xclang -iwithsysroot/lib/libcxxabi/include -Xclang -iwithsysroot/include/compat -Xclang -iwithsysroot/include/libc -Xclang -iwithsysroot/lib/libc/musl/arch/emscripten -Xclang -iwithsysroot/local/include -Xclang -iwithsysroot/include/SSE -Xclang -iwithsysroot/include/neon -Xclang -iwithsysroot/lib/compiler-rt/include -Xclang -iwithsysroot/lib/libunwind/include --target=wasm32-unknown-unknown-wasm --optimize=3 -v ./lttb.cpp -c -o /var/folders/xj/yxtdtt1n42l5m_6pxn_1yspw0000gn/T/emscripten_temp_ukq5xqc_/lttb_0.o' failed (1)
```
**lltb.c**
```
// quick_example.cpp
#undef __APPLE__ // https://github.com/microsoft/vscode-cpptools/issues/1083#issuecomment-338499236
#include
#include "lttb.hpp"
using namespace emscripten;
struct DataPoint
{
float x;
float y;
};
void readData(DataPoint in[], int data_length, float *x, float *y)
{
for (int i = 0; i < data_length; i++)
{
in[i].x = x[i];
in[i].y = y[i];
}
}
void lttb(float *x, float *y, int data_length, int max_points, float *downsampled_x, float *downsampled_y)
{
using PointLttb = LargestTriangleThreeBuckets;
DataPoint in[data_length];
readData(in, data_length, x, y);
DataPoint out[max_points];
PointLttb::Downsample(in, data_length, out, max_points);
*downsampled_x = out[0].x;
*downsampled_y = out[0].y;
return;
}
EMSCRIPTEN_BINDINGS(lttb_module)
{
function("lttb", <tb, allow_raw_pointers());
}
```
**lttb.h**
```
#ifndef __LTTP_HPP__
#define __LTTP_HPP__
#include
#include
#include
#include
template
struct LargestTriangleThreeBuckets
{
template
static void Downsample(InputIt source, size_t sourceSize, OutputIt destination, size_t destinationSize)
{
if (destinationSize == 0)
{
return;
}
if (destinationSize >= sourceSize)
{
std::copy_n(source, sourceSize, destination);
}
*destination = *source;
++destination;
TData every = static_cast(sourceSize - 2) / (destinationSize - 2);
size_t aIndex = 0;
for (size_t i = 0; i < destinationSize - 2; ++i)
{
size_t avgRangeStart = static_cast((i + 1) * every) + 1;
size_t avgRangeEnd = static_cast((i + 2) * every) + 1;
if (avgRangeEnd > sourceSize)
{
avgRangeEnd = sourceSize;
}
TData avgRangeLength = avgRangeEnd - avgRangeStart;
TData avgX = 0;
TData avgY = 0;
for (; avgRangeStart < avgRangeEnd; ++avgRangeStart)
{
avgX += source[avgRangeStart].*x;
avgY += source[avgRangeStart].*y;
}
avgX /= avgRangeLength;
avgY /= avgRangeLength;
size_t rangeOffs = static_cast(i * every) + 1;
size_t rangeTo = static_cast((i + 1) * every) + 1;
TData pointAX = source[aIndex].*x;
TData pointAY = source[aIndex].*y;
TData maxArea = -1;
size_t nextAIndex = 0;
for (; rangeOffs < rangeTo; ++rangeOffs)
{
TData area = std::abs(
(pointAX - avgX) * (source[rangeOffs].*y - pointAY) -
(pointAX - source[rangeOffs].*x) * (avgY - pointAY)) /
2;
if (area > maxArea)
{
maxArea = area;
nextAIndex = rangeOffs;
}
}
*destination = source[nextAIndex];
++destination;
aIndex = nextAIndex;
}
*destination = source[sourceSize - 1];
++destination;
}
};
#endif
```
**Compile:**
```
emcc ./lttb.cpp \
--target=wasm32-unknown-unknown-wasm \
--optimize=3 \
-v \
-nostdlib \
-Wl,--export-all \
-Wl,--no-entry \
-Wl,--allow-undefined \
-s ALLOW_MEMORY_GROWTH=1 \
-o lttb.wasm
```
**Environment**
**_macOS:_**
10.15.5
**_clang++_:**
Apple clang version 12.0.0 (clang-1200.0.32.21)
Target: x86_64-apple-darwin19.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
**_emcc_:**
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 2.0.12
clang version 12.0.0 (https://github.com/llvm/llvm-project.git 52e240a0721e4120a7143f6f5bab4760d28d48e8)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /usr/local/opt/emscripten/libexec/llvm/bin
**Related Issues:**
[https://github.com/emscripten-core/emscripten/issues/8566](https://github.com/emscripten-core/emscripten/issues/8566)
[https://github.com/emscripten-core/emscripten/issues/8569](https://github.com/emscripten-core/emscripten/issues/8569)
Contributor guide
Assessment
This issue has not been assessed yet.