Reputation: 115
I am following a tutorial on building an audio classifier here and when reach to the step where I run the sh build.sh I get the cannot find -lc++
error.
Kindly, any advice on how to fix this error would be highly appreciated.
Building standalone classifier
mkdir -p build
rm -rf *.gcda
rm -rf *.gcno
clang -c -DTF_LITE_DISABLE_X86_NEON -Wall -I. -Isource -Iedge-impulse-sdk/ -Iedge-impulse-sdk/tensorflow -Iedge-impulse-sdk/third_party -Iedge-impulse-sdk/third_party/flatbuffers -Iedge-impulse-sdk/third_party/flatbuffers/include -Iedge-impulse-sdk/third_party/flatbuffers/include/flatbuffers -Iedge-impulse-sdk/third_party/gemmlowp/ -Iedge-impulse-sdk/third_party/gemmlowp/fixedpoint -Iedge-impulse-sdk/third_party/gemmlowp/internal -Iedge-impulse-sdk/third_party/ruy -Imodel-parameters -Itflite-model -Iedge-impulse-sdk/anomaly -Iedge-impulse-sdk/classifier -Iedge-impulse-sdk/dsp -Iedge-impulse-sdk/dsp/kissfft -Iedge-impulse-sdk/porting -lc++ -lm edge-impulse-sdk/tensorflow/lite/c/common.c -o build/common.o
clang: warning: -lc++: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: -lm: 'linker' input unused [-Wunused-command-line-argument]
clang++ -DTF_LITE_DISABLE_X86_NEON -std=c++11 -Wall -I. -Isource -Iedge-impulse-sdk/ -Iedge-impulse-sdk/tensorflow -Iedge-impulse-sdk/third_party -Iedge-impulse-sdk/third_party/flatbuffers -Iedge-impulse-sdk/third_party/flatbuffers/include -Iedge-impulse-sdk/third_party/flatbuffers/include/flatbuffers -Iedge-impulse-sdk/third_party/gemmlowp/ -Iedge-impulse-sdk/third_party/gemmlowp/fixedpoint -Iedge-impulse-sdk/third_party/gemmlowp/internal -Iedge-impulse-sdk/third_party/ruy -Imodel-parameters -Itflite-model -Iedge-impulse-sdk/anomaly -Iedge-impulse-sdk/classifier -Iedge-impulse-sdk/dsp -Iedge-impulse-sdk/dsp/kissfft -Iedge-impulse-sdk/porting -lc++ -lm source/*.cpp edge-impulse-sdk/dsp/kissfft/*.cpp edge-impulse-sdk/dsp/dct/*.cpp edge-impulse-sdk/tensorflow/lite/kernels/*.cc edge-impulse-sdk/tensorflow/lite/kernels/internal/*.cc edge-impulse-sdk/tensorflow/lite/micro/kernels/*.cc edge-impulse-sdk/tensorflow/lite/micro/*.cc edge-impulse-sdk/tensorflow/lite/micro/memory_planner/*.cc edge-impulse-sdk/tensorflow/lite/core/api/*.cc ./edge-impulse-sdk/dsp/memory.cpp edge-impulse-sdk/porting/posix/*.c* build/common.o -o build/edge-impulse-standalone
/usr/bin/ld: cannot find -lc++
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Makefile.tflite:36: recipe for target 'build' failed
make: *** [build] Error 1
Upvotes: 9
Views: 54417
Reputation: 1039
I think your build configuration is telling the compiler to use the standard c++ library from clang (LLVM).
That is a possible choice, and certainly not a bad one. However it is not the only choice for a standard c++ library. There are at last two commonly used standard c++ libraries: the very broadly used GNU standard c++ library libstdc++, and the slightly more modern libc++. Both libraries are good. But since the GNU version is more commonly used (as of the time of this writing), you may run into less problems using this one instead.
To control the choice of the standard c++ library, the compiler flag -stdlib=xxx
can be used. In your case, this flag seems to be set to libc++
, or your compiler defaults to libc++
.
Note that a common problem can be that the libc++
development files are not installed along with the clang compiler by default. So it is well possible that all you need to do is to install the missing libraries, and everything will work.
You do have at least two options:
15
with your actual version):sudo apt install libc++-15-dev libc++abi-15-dev
libstdc++
, it is usually sufficient to remove the -stdlib=libc++
flag from your build configuration, for example from CMakeLists.txt
. It may also be possible that your compiler defaults to using libc++
, in which case you would need to add the flag -stdlib=libstdc++
to actively choose the GNU version.Upvotes: 14
Reputation: 1
Replace clang
by clang++
or g++
. Then -lc++
becomes "automagically" linked.
Of course, spend a few days reading the documentation of GCC and of Clang (and of ld
from binutils; since both clang++
and g++
are running ld
). Read carefully about invoking GCC. The order of program arguments to g++
(and also to clang++
) are important.
Since you use GNU make, you obviously need to spend a day reading its documentation.
PS. Budget perhaps a week of work in reading documentation.
Upvotes: 1