Emscripten xlocale.h error

267 views
Skip to first unread message

Arvind Arya

unread,
Dec 4, 2021, 8:00:47 AM12/4/21
to emscripten-discuss

I built my opencv libraries for WebAssembly and have a simple program,My Program:

#include"opencv2/opencv.hpp"
#include<iostream>
#include<emscripten.h>

using namespace std;
using namespace cv;

int main(){
cout<<"Let's see\n";
uint8_t uarr[] = {1,2,3,4,5,6,7,8,9,10,11,12};
int rows=2;
int cols=2;
Mat mat1(rows,cols,CV_8UC3, uarr);

cout<<"Put oil in the car: "<<mat1<<"\n";
return 1;
}

My CMakeLists.txt:


cmake_minimum_required( VERSION 3.1 )
set( CMAKE_CXX_STANDARD 11 )
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
project( HelloCV )

# Does not work
# find_package( OpenCV REQUIRED PATHS third-party/opencv-4.1.0/build_wasm NO_DEFAULT_PATH)

# Needed for opencv2/opencv.hpp
include_directories( /Users/arvindarya/Desktop/aspen/opencv/include )

# Needed by opencv.hpp for opencv2/opencv_modules.hpp
include_directories( /Users/arvindarya/Desktop/aspen/opencv/build_wasm )

# Needed by opencv_modules.hpp for every module
file( GLOB opencv_include_modules "/Users/arvindarya/Desktop/aspen/opencv/modules/*/include" )
include_directories( ${opencv_include_modules} )

# Our hello world executable
add_executable( hello image.cpp )

# Link to opencv.js precompiled libraries
file( GLOB opencv_js "/Users/arvindarya/Desktop/aspen/opencv/build_wasm/lib/*.a" )
target_link_libraries( hello ${opencv_js} )


I am running

emmake cmake .

and

make

I am getting an error:

clang-14: warning: argument unused during compilation: '-mmacosx-version-min=10.15' [-Wunused-command-line-argument]

In file included from /Users/arvindarya/Desktop/aspen/image.cpp:3:

In file included from /Users/arvindarya/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1/iostream:37:

In file included from /Users/arvindarya/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1/ios:215:

/Users/arvindarya/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1/__locale:40:11: fatal error: 'xlocale.h' file not found

# include <xlocale.h>

          ^~~~~~~~~~~

1 error generated.

em++: error: '/Users/arvindarya/emsdk/upstream/bin/clang++ -target wasm32-unknown-emscripten -DEMSCRIPTEN -fignore-exceptions -fvisibility=default -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -D__EMSCRIPTEN_major__=3 -D__EMSCRIPTEN_minor__=0 -D__EMSCRIPTEN_tiny__=0 -D_LIBCPP_ABI_VERSION=2 -Werror=implicit-function-declaration -Xclang -iwithsysroot/include/SDL --sysroot=/Users/arvindarya/emsdk/upstream/emscripten/cache/sysroot -Xclang -iwithsysroot/include/compat -I/Users/arvindarya/Desktop/aspen/opencv/include -I/Users/arvindarya/Desktop/aspen/opencv/build_wasm -I/Users/arvindarya/Desktop/aspen/opencv/modules/calib3d/include -I/Users/arvindarya/Desktop/aspen/opencv/modules/core/include -I/Users/arvindarya/Desktop/aspen/opencv/modules/dnn/include -I/Users/arvindarya/Desktop/aspen/opencv/modules/features2d/include -I/Users/arvindarya/Desktop/aspen/opencv/modules/flann/include -I/Users/arvindarya/Desktop/aspen/opencv/modules/gapi/include -I/Users/arvindarya/Desktop/aspen/opencv/modules/highgui/include -I/Users/arvindarya/Desktop/aspen/opencv/modules/imgcodecs/include -I/Users/arvindarya/Desktop/aspen/opencv/modules/imgproc/include -I/Users/arvindarya/Desktop/aspen/opencv/modules/ml/include -I/Users/arvindarya/Desktop/aspen/opencv/modules/objdetect/include -I/Users/arvindarya/Desktop/aspen/opencv/modules/photo/include -I/Users/arvindarya/Desktop/aspen/opencv/modules/stitching/include -I/Users/arvindarya/Desktop/aspen/opencv/modules/ts/include -I/Users/arvindarya/Desktop/aspen/opencv/modules/video/include -I/Users/arvindarya/Desktop/aspen/opencv/modules/videoio/include -I/Users/arvindarya/Desktop/aspen/opencv/modules/world/include -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk -mmacosx-version-min=10.15 -std=gnu++11 -MD -MT CMakeFiles/hello.dir/image.cpp.o -MF CMakeFiles/hello.dir/image.cpp.o.d -c /Users/arvindarya/Desktop/aspen/image.cpp -o CMakeFiles/hello.dir/image.cpp.o' failed (returned 1)

make[2]: *** [CMakeFiles/hello.dir/image.cpp.o] Error 1

make[1]: *** [CMakeFiles/hello.dir/all] Error 2

make: *** [all] Error 2


Can anyone help me with this.I want to run a WebAssembly with some opencv this is the most basic code. Is something wrong with my CMake. I cannot even get <iostream> work there is something seriously wrong. Please help me. I have tried emcc --clear-cache it does not work.

Floh

unread,
Dec 5, 2021, 10:08:33 AM12/5/21
to emscripten-discuss
Just a shot in the dark, but this -isysroot option might cause problems (and the following Mac-specific option doesn't look right either):

-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk -mmacosx-version-min=10.15

Maybe this causes a mixup of C++ stdlib headers in the Emscripten SDK and the Xcode SDKs.

Looking at your CMakeLists.txt file I have no idea where those macOS specific build options would come from though.

One very obscure problem I've seen in the past is that global environment variables might pollute your Emscripten build options (e.g. run "env" and check the output for anything suspicious). I've seen this with the CPATH variable (however your problem looks different - but maybe there are other env variables which influence the build).

To find out whether the problem is in your system setup you could try building my Pacman clone here:


If this also fails, the problem could be in your setup (however this is a plain C project, which is a much easier case than a C++ project using the C++ stdlib).

Cheers,
-Floh.

Arvind Arya

unread,
Dec 6, 2021, 3:45:32 AM12/6/21
to emscripten-discuss

Thank You for your reply. I ran this Pacman project and it built and ran . I read on it and apple has made Macs 32 bit incompatible post OSX 15 could this be the problem. I will try to run this in a windows environment and get back to you
Message has been deleted

Arvind Arya

unread,
Dec 6, 2021, 9:06:45 AM12/6/21
to emscripten-discuss
Can you please confirm this I have this program the very basic program I can find and the CMakeLists.txt to go with it. I cannot get it to compile to WASM using Emscripten. Can you please check out and tell me if it gets made because I have done everything right I think. The CMake and the Make part is giving me trouble. Can you please please check it out. I have spent weeks on this issue and I would be forever grateful if you could check it out. I just don't know about emmake and from what I have gathered this should work. 

Floh

unread,
Dec 7, 2021, 7:54:52 AM12/7/21
to emscripten-discuss
Your project builds and runs fine here (M1 Mac) using the following inputs (after '>') mixed with console outputs:

...
> cd new_opencv_repo
> mkdir build
> cd build
> emcmake cmake -G"Unix Makefiles" ..
configure: cmake "-GUnix Makefiles" .. -DCMAKE_TOOLCHAIN_FILE=/Users/floh/projects/fips-sdks/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_CROSSCOMPILING_EMULATOR=/Users/floh/projects/fips-sdks/emsdk/node/14.15.5_64bit/bin/node
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/floh/scratch/new_opencv_repo/build
> cmake --build .
[ 50%] Building CXX object CMakeFiles/hello.dir/image.cpp.o
[100%] Linking CXX executable hello.js
[100%] Built target hello
> ls
CMakeCache.txt      CMakeFiles          Makefile            cmake_install.cmake hello.js            hello.wasm
> node hello.js
Let's see
Put oil in the car: [  1,   2,   3,   4,   5,   6;
   7,   8,   9,  10,  11,  12]

Arvind Arya

unread,
Dec 7, 2021, 1:34:29 PM12/7/21
to emscripten-discuss

Thank you very much. It was a very weird error. I did not include the DCMAKE_CROSSCOMPILLING_EMULATOR and "Unix Makefiles" attribute. 
The literature online is not very noob friendly.
 I appreciate your help very much. 
It compiled.
Thanks,
Arvind
Reply all
Reply to author
Forward
0 new messages