Skip to content
GitLab
  • Menu
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • CMake CMake
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,927
    • Issues 3,927
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 19
    • Merge requests 19
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Releases
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • External wiki
    • External wiki
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • CMake
  • CMakeCMake
  • Issues
  • #17863
Closed
Open
Created Mar 30, 2018 by Tom Hughes@thughes

Android NDK always records runtime dependency against stdc++

Regardless of the CMAKE_ANDROID_STL_TYPE chosen (e.g., c++_static), all shared libraries and executables built with the Android NDK are linked against stdc++.

I'm attaching a simple test case that reproduces the issue (change NDK_ROOT in run.sh to point to the NDK and then run run.sh): CMakeLists.txt run.sh test_lib.cc test.cc

Newer versions of clang support the nostdlib++ flag, but the latest stable NDK (16b) does not have a version of clang with that flag: https://reviews.llvm.org/D35780

Also see this NDK issue: https://github.com/android-ndk/ndk/issues/105

As a workaround, you can use the C compiler to link instead of the C++ compiler in your project:

string(REPLACE "CMAKE_CXX_COMPILER" "CMAKE_C_COMPILER" CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY}")
string(REPLACE "CMAKE_CXX_COMPILER" "CMAKE_C_COMPILER" CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE}")
link_libraries(m)

Another option is to set -nodefaultlibs and manually add in the necessary libs: https://github.com/android-ndk/ndk/issues/105#issuecomment-327409972

Edited Apr 02, 2018 by Tom Hughes
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking