clang++: error: linker command failed with exit code 1

[100%] Linking CXX shared library libexamplemgr.so
/home/user/work/external/android_tools/ndk/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: cannot find -lbase
/home/user/work/external/android_tools/ndk/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: cannot find -lcommon
/home/user/work/external/android_tools/ndk/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: cannot find -lconnection
/home/user/work/external/android_tools/ndk/android-ndk-r21e/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: cannot find -lbreakpad
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

在我自己的项目中使用cmake编译报这个error: linker command failed with exit code 1,前面的这四个库,第四个breakpad是第三方,剩下三个我并没有base、common、connection这三个库,他为什么要去NDK里找这三个库?

img

感觉这个提示挺清楚的,就是有些静态库找不到,你这个环境下有没有 ?

  • 这篇博客: c++编译器配置错误问题clang: error: linker command failed with exit code 1 (use -v to see invocation)中的 解决方案: 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
  • 1.cmake在第一次编译的时候开始会输出使用的c和cxx编译器,如下:

     cmake ..
    -- The C compiler identification is GNU 7.5.0
    -- The CXX compiler identification is Clang 6.0.0
    -- Check for working C compiler: /usr/bin/cc
    -- Check for working C compiler: /usr/bin/cc -- works
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Detecting C compile features
    -- Detecting C compile features - done
    -- Check for working CXX compiler: /usr/bin/c++
    -- Check for working CXX compiler: /usr/bin/c++ -- works
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Detecting CXX compile features
    ...

    2.更新c++默认编译器

    由于之前已经删除了g++-7对应的编译器链接,所以执行 sudo update-alternatives --config g++ 显示

    sudo update-alternatives --config c++
    There is only one alternative in link group c++ (providing /usr/bin/c++): /usr/bin/clang++-libc++
    Nothing to configure.
    

    添加g++编译器到group c++

    sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 100
    

    再次执行即可看到:默认编译器已经切换为g++

    sudo update-alternatives --config c++
    There are 2 choices for the alternative c++ (providing /usr/bin/c++).
    
      Selection    Path                     Priority   Status
    ------------------------------------------------------------
    * 0            /usr/bin/g++              100       auto mode
      1            /usr/bin/clang++-libc++   5         manual mode
      2            /usr/bin/g++              100       manual mode
    
    Press <enter> to keep the current choice[*], or type selection number: 

    查看编译器版本g++-7

    ll /usr/bin/g++
    lrwxrwxrwx 1 root root 5 5月  21  2019 /usr/bin/g++ -> g++-7*
    

    后续升级编译器也是类似操作.

    3.验证测试

    删除项目的build内容,重新编译查看cmake默认编译器均为GNU 7.5.0, 正常!

    cmake ..
    -- The C compiler identification is GNU 7.5.0
    -- The CXX compiler identification is GNU 7.5.0
    -- Check for working C compiler: /usr/bin/cc
    -- Check for working C compiler: /usr/bin/cc -- works
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Detecting C compile features
    -- Detecting C compile features - done
    -- Check for working CXX compiler: /usr/bin/c++
    -- Check for working CXX compiler: /usr/bin/c++ -- works