Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix android libc++ build #7174

Merged
merged 1 commit into from Sep 2, 2016
Merged

Conversation

guycook
Copy link
Contributor

@guycook guycook commented Aug 26, 2016

resolves #6511

This pullrequest changes

Presently, when using cmake -DANDROID_STL=c++_shared the build completes successfully but you can't actually use the generated artefacts in an android project that uses clang + libc++ due to linker errors. The changes in this PR resolve that by using the correct std library headers.

@vpisarev
Copy link
Contributor

@mshabunin, could you please review it?

@alalek
Copy link
Member

alalek commented Aug 26, 2016

@guycook What Android NDK do you use?

@guycook
Copy link
Contributor Author

guycook commented Aug 27, 2016

@alalek I've tested and got it working with two separate ndk versions:

To use the built library I'm using Android Studio + gradle-experimental:0.8.0-beta2 and a build script that looks like:

model {
    android {
        ndk {
            toolchain "clang"
            stl "c++_shared"
            abiFilters.add("armeabi-v7a")
            cppFlags.add("-std=c++11")
            cppFlags.add("-DNDEBUG")
            cppFlags.add("-DANDROID")
            cppFlags.add("-I" + localProperty('opencv.native') + "/jni/include")
            ldFlags.add("-L" + localProperty('opencv.native') + "/libs/armeabi-v7a")
            ldFlags.add("-L" + localProperty('opencv.native') + "/3rdparty/libs/armeabi-v7a")
            ldLibs.add("opencv_core")
            ldLibs.add("tegra_hal")
            ldLibs.add("tbb")
            ldLibs.add("zlib")
        }
    }
}

The relevant cmake flags are:

ANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-clang3.5
ANDROID_STL=c++_shared
ANDROID_ABI="armeabi-v7a"
ANDROID_NATIVE_API_LEVEL=21
CMAKE_C_FLAGS_RELEASE="-Os -DNDEBUG -DANDROID -fvisibility=hidden -ffunction-sections -fstack-protector-all"
CMAKE_CXX_FLAGS_RELEASE="-Os -DNDEBUG -DANDROID -fvisibility=hidden -ffunction-sections -fstack-protector-all -fvisibility-inlines-hidden"
ENABLE_PRECOMPILED_HEADERS=OFF
CMAKE_TOOLCHAIN_FILE=platforms/android/android.toolchain.cmake

@@ -40,6 +40,7 @@
#include "common.hpp"

#include <vector>
#include <cstdlib>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This statement should be moved to "comon.hpp", because some other source files in Carotene need it too (e.g. canny.cpp).

@mshabunin
Copy link
Contributor

Thank you! Please squash both commits into one and we will merge it.

@guycook
Copy link
Contributor Author

guycook commented Sep 1, 2016

@mshabunin Cool, I think that's done now (I haven't ever squashed before)

@mshabunin
Copy link
Contributor

👍

@opencv-pushbot opencv-pushbot merged commit e06a9e9 into opencv:master Sep 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Targeting Android clang/c++stl not possible.
5 participants