emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.81k stars 3.31k forks source link

#include <memory> file not found #11328

Closed andypotato closed 4 years ago

andypotato commented 4 years ago

Error description

Using emscripten v1.39.16 on Ubuntu 18.04 trying to compile a c++ file with emcc results in the following error:

fatal error: 'memory' file not found
#include <memory>
         ^~~~~~~~
1 error generated.

Additional output

emcc: error: '/mnt/c/Tools/emsdk/upstream/bin/clang -target wasm32-unknown-emscripten -D__EMSCRIPTEN_major__=1 -D__EMSCRIPTEN_minor__=39 -D__EMSCRIPTEN_tiny__=16 -D_LIBCPP_ABI_VERSION=2 -Dunix -D__unix -D__unix__ -Werror=implicit-function-declaration -Xclang -nostdsysteminc -Xclang -isystem/mnt/c/Tools/emsdk/upstream/emscripten/system/include/compat -Xclang -isystem/mnt/c/Tools/emsdk/upstream/emscripten/system/include -Xclang -isystem/mnt/c/Tools/emsdk/upstream/emscripten/system/include/libc -Xclang -isystem/mnt/c/Tools/emsdk/upstream/emscripten/system/lib/libc/musl/arch/emscripten -Xclang -isystem/mnt/c/Tools/emsdk/upstream/emscripten/system/local/include -Xclang -isystem/mnt/c/Tools/emsdk/upstream/emscripten/cache/wasm/include -DEMSCRIPTEN -fignore-exceptions -fno-inline-functions -I/mnt/c/Users/as/Documents/Development/github/artoolkit5-js/lib/artoolkit5/include -I/mnt/c/Users/as/Documents/Development/github/artoolkit5-js/src/artoolkit5/ -I/mnt/c/Users/as/Documents/Development/github/artoolkit5-js/lib/ -I/mnt/c/Users/as/Documents/Development/github/artoolkit5-js/lib/artoolkit5/lib/SRC/KPM/FreakMatcher -Oz -D HAVE_NFT /mnt/c/Users/as/Documents/Development/github/artoolkit5-js/lib/artoolkit5/lib/SRC/KPM/kpmHandle.cpp -Xclang -isystem/mnt/c/Tools/emsdk/upstream/emscripten/system/include/SDL -c -o /tmp/emscripten_temp__h6fe1k3/kpmHandle_93.o -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr' failed (1)

Expected result

The system has libstdc++ installed and memory is available at its default location at /usr/include/c++/7.5.0/memory. As emscripten selected this gcc version, the compiler should be able to find the library.

Debug output

$ emcc -v
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 1.39.16
clang version 11.0.0 (/b/s/w/ir/cache/git/chromium.googlesource.com-external-github.com-llvm-llvm--project 3774bcf9f84520a8c35bf765d9a528040d68a14b)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /mnt/c/Tools/emsdk/upstream/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0
Candidate multilib: .;@m64
Selected multilib: .;@m64
shared:INFO: (Emscripten: Running sanity checks)
kripken commented 4 years ago

The system has libstdc++ installed and memory is available at its default location at /usr/include/c++/7.5.0/memory

Emscripten is a cross-compiler, really - it can't use system headers. For example, wasm is a 32-bit architecture, but your system headers are likely for a 64-bit machine.

Emscripten ships with libc++ which includes memory,

// a.cpp
#include <memory>

That compiles with em++ a.cpp.

sbc100 commented 4 years ago

I think the problem here is that the compiler is running in C and not C++ mode

What command line are you using? Doesn't you file have a C++ file extension?

You can ensure C++ mode in one of 3 ways:

  1. Run with em++
  2. Make sure you input files have C++ exceptions (.cxx, .cc, .cpp, etc)
  3. Pass -x c++ on the command line.
andypotato commented 4 years ago

What command line are you using? Doesn't you file have a C++ file extension?

The build command includes files with both .c and .cpp extensions. I guess you're right and the compiler runs in C mode only which fails to compile C++ files even they are properly named.

The weird thing is, this build used to run without issues in a previous 1.38.xx version of emscripten. I just recently changed to a new machine and had to create a fresh install.

Forcing C++ mode with em++ or the -x flag will break the build due to treating 'c' input as 'c++' when in C++ mode. But shouldn't it use the appropriate compiler based on file extension?

Full build command below:

emcc
-I/home/as/src/artoolkit5-js/lib/artoolkit5/include
-I/home/as/src/artoolkit5-js/src/artoolkit5/
-I/home/as/src/artoolkit5-js/lib/
-I/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/KPM/FreakMatcher
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/AR/arLabelingSub/*.c
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/AR/*.c
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/ARICP/*.c
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/ARMulti/*.c
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/Video/video.c
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/ARUtil/log.c
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/ARUtil/file_utils.c
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/AR2/handle.c
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/AR2/imageSet.c
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/AR2/jpeg.c
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/AR2/marker.c
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/AR2/featureMap.c
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/AR2/featureSet.c
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/AR2/selectTemplate.c
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/AR2/surface.c
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/AR2/tracking.c
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/AR2/tracking2d.c
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/AR2/matching.c
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/AR2/matching2.c
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/AR2/template.c
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/AR2/searchPoint.c
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/AR2/coord.c
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/AR2/util.c
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/KPM/kpmHandle.cpp
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/KPM/kpmRefDataSet.cpp
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/KPM/kpmMatching.cpp
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/KPM/kpmResult.cpp
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/KPM/kpmUtil.cpp
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/KPM/kpmFopen.c
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/KPM/FreakMatcher/detectors/DoG_scale_invariant_detector.cpp
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/KPM/FreakMatcher/detectors/gaussian_scale_space_pyramid.cpp
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/KPM/FreakMatcher/detectors/gradients.cpp
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/KPM/FreakMatcher/detectors/harris.cpp
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/KPM/FreakMatcher/detectors/orientation_assignment.cpp
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/KPM/FreakMatcher/detectors/pyramid.cpp
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/KPM/FreakMatcher/facade/visual_database_facade.cpp
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/KPM/FreakMatcher/matchers/hough_similarity_voting.cpp
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/KPM/FreakMatcher/matchers/freak.cpp
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/KPM/FreakMatcher/framework/date_time.cpp
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/KPM/FreakMatcher/framework/image.cpp
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/KPM/FreakMatcher/framework/logger.cpp
/home/as/src/artoolkit5-js/lib/artoolkit5/lib/SRC/KPM/FreakMatcher/framework/timers.cpp
-Oz
-Wno-warn-absolute-paths
-s TOTAL_MEMORY=268435456
-s USE_ZLIB=1
-s USE_LIBJPEG
-s "EXTRA_EXPORTED_RUNTIME_METHODS=['FS']"
--memory-init-file 0
--bind
-D HAVE_NFT
-o /home/as/src/artoolkit5-js/src/artoolkit5/libar.bc
sbc100 commented 4 years ago

Oh yes this does look like a bug. We should use the correct mode for each input file according to its extension.

However, I would advise changing your build system to build each source file in isolation and and link them together as a separate step. Is there some reason you are trying to build eveything and link it together in a single command?

F6272 commented 1 year ago

Can you unpack a file from Winrar?