/usr/bin/ld: cannot find -lc++

Viewed 10854

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
2 Answers

I think your build configuration is instructing clang to use the standard c++ library from LLVM. That is one possible choice, but not the only one, and not strictly required. You can read more about this standard library implementation on the libc++ website. Basically, its a relatively modern version of where gcc typically uses the GNU standard c++ library libstdc++.

To control the choice of the standard c++ library, the compiler flag -stdlib=xxx can be used. In your case this seems to be set to libc++.

Now a common problem can be that the libc++ development files are not installed along with clang by default. So it is well possible that your LLVM installation is just missing the libraries to link with.

You do have a number of options:

  • Choose a different standard c++ library, like the more common GNU standard c++ library libstdc++. To do that, find a way to remove -stdlib=xxx from your build configuration.
  • Install the LLVM standard c++ library. On Ubuntu, with an upstream clang from llvm.org, you can install the libraries for example with (replace 14 with your actual version):
sudo apt install libc++-14-dev libc++abi-14-dev

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.

Related