/usr/bin/ld: 找不到 -lc++

san*_*and 8 c++ clang

我正在遵循此处构建音频分类器的教程,当到达运行 sh build.sh 的步骤时,我收到错误cannot find -lc++

恳请您提供有关如何修复此错误的任何建议,我们将不胜感激。

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
Run Code Online (Sandbox Code Playgroud)

emm*_*lau 12

我认为您的构建配置告诉编译器使用 clang (LLVM) 中的标准 c++ 库。

这是一种可能的选择,而且当然不是一个糟糕的选择。然而它并不是标准 C++ 库的唯一选择。最后有两个常用的标准 C++ 库:使用非常广泛的 GNU 标准 C++ 库libstdc++和稍微更现代的libc++。两个库都不错。但由于 GNU 版本更常用(截至撰写本文时),因此使用此版本可能会遇到更少的问题。

要控制标准 C++ 库的选择,-stdlib=xxx可以使用编译器标志。在您的情况下,此标志似乎设置为libc++,或者您的编译器默认为libc++

请注意,一个常见问题可能是libc++默认情况下开发文件未与 clang 编译器一起安装。因此,很可能您所需要做的就是安装缺少的库,一切都会正常。

你至少有两个选择:

  • 安装 LLVM 标准 C++ 库,以防丢失。在 Ubuntu 上,使用来自 llvm.org 的上游 clang,您可以使用以下命令安装这些库(替换15为您的实际版本):
sudo apt install libc++-15-dev libc++abi-15-dev
Run Code Online (Sandbox Code Playgroud)
  • 选择不同的标准 C++ 库。要使用更常见的 GNU 标准 c++ 库libstdc++,通常从构建配置中删除该-stdlib=libc++标志就足够了,例如从CMakeLists.txt. 您的编译器也可能默认使用libc++,在这种情况下,您需要添加该标志-stdlib=libstdc++来主动选择 GNU 版本。

  • clang 调用 ld. 安装 libc++-15-dev 和 libc++abi-15-dev 后,我的 ld 调用仍然失败,因为 libstdc++.so 不存在。我能够用 sudo ln -s /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.30 /usr/lib/x86_64-linux-gnu/libstdc++.so 解决这个问题,请考虑将其添加到答案中。 (2认同)

Bas*_*tch 1

替换clangclang++g++。然后-lc++就变成“自动”链接了。

当然,花几天时间阅读GCCClang的文档(以及binutilsld的文档;因为 和 都在 运行)。仔细阅读有关调用 GCC 的信息。程序参数的顺序(以及)很重要。clang++g++ldg++clang++

由于您使用GNU make,因此您显然需要花一天时间阅读其文档。

附言。预算大约一周的阅读文档的工作量。