[CMake] Android NDK, clang, and ODR violations
Christopher Broadbent
chris at macolighting.com
Wed Jul 26 23:30:30 EDT 2017
I'm in the progress of updating some code to clang in the NDK (since
they are not longer supporting GCC), and getting some ODR errors which
seem to be caused by a bad link configuration.
The generated executables / shared libraries seem to link to both the
selected standard library, and libstdc++.so (android's minimal 'system'
standard lib, not gcc's c++ standard lib). This causes multiple
definitions of new/delete, triggering ODR warnings between 'libc++abi.a'
and 'libstdc++.so'
When using the gnustl_static, there's similar issues on the members of
'std::type_info', 'std::basic_string', and 'std::shared_ptr', but this
is now between our code and 'libgnustl_static.a' (possibly a clang vs
gcc code gen difference?)
This happens in cmake 3.7.2 and cmake 3.8
Is anyone successfully using cmake + clang on android, or have an idea
of where the configuration script might be wrong?
Here is my reproduction:
--- toolchain.cmake
set(CMAKE_SYSTEM_NAME Android)
set(CMAKE_SYSTEM_VERSION 19)
set(CMAKE_ANDROID_ARCH_ABI armeabi-v7a)
set(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION clang)
set(CMAKE_ANDROID_STL_TYPE c++_static)
--- CMakeLists.txt
cmake_minimum_required(VERSION 3.7.2)
cmake_policy(VERSION 3.7.2)
project(reproduction)
string(APPEND CMAKE_EXE_LINKER_FLAGS " -Wl,--detect-odr-violations")
add_executable(main main.cpp)
--- main.cpp
#include <iostream>
int main() {
std::cout << "hello, world!\n";
}
---
Thanks,
Chris
More information about the CMake
mailing list