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

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

本文关键字:find -lc++ cannot ld usr bin      更新时间:2023-10-16

我正在这里按照构建音频分类器的教程进行操作,当到达运行 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

我认为您的构建配置告诉编译器使用来自 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
  • 选择其他标准 c++ 库。要使用更常见的GNU标准c++库libstdc++,通常只需从构建配置中删除-stdlib=libc++标志就足够了,例如从CMakeLists.txt中删除。也可能您的编译器默认使用libc++,在这种情况下,您需要添加标志-stdlib=libstdc++以主动选择 GNU 版本。

clang替换为clang++g++。然后-lc++变得"自动"链接。

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

由于你使用GNU make,你显然需要花一天时间阅读它的文档。

预算也许是一周的阅读文档的工作。