简体   繁体   中英

ndk r20 ld : ld: error: cannot find -lpthread

I'm trying to build tesseract for android arm with vcpkg and ndk r20 I had to edit CMakeLists.txt and add glob.c and glob.h because they weren't in the ndk

I also made fileio.cpp include glob.h

then I had to bypass pkg-config because ndk doesn't have it I replace this :

if(NOT EXISTS ${PROJECT_SOURCE_DIR}/.cppan)
    if (NOT Leptonica_DIR AND NOT MSVC)
        find_package(PkgConfig REQUIRED)
        pkg_check_modules(Leptonica REQUIRED lept>=${MINIMUM_LEPTONICA_VERSION})
        #link_directories(${Leptonica_LIBRARY_DIRS})
    else()
        find_package(Leptonica ${MINIMUM_LEPTONICA_VERSION} REQUIRED CONFIG)
    endif()
else()
    if (STATIC)
        set(CPPAN_BUILD_SHARED_LIBS 0)
    else()
        set(CPPAN_BUILD_SHARED_LIBS 1)
    endif()
    add_subdirectory(.cppan)
endif()

with this :

if(NOT EXISTS ${PROJECT_SOURCE_DIR}/.cppan)
    if (NOT Leptonica_DIR AND NOT MSVC)
        find_package(Leptonica CONFIG REQUIRED)
        #link_libraries(tesseract leptonica) causes errors , tried tesseractlib instead of tesseract
    else()
        find_package(Leptonica ${MINIMUM_LEPTONICA_VERSION} REQUIRED CONFIG)
    endif()
else()
    if (STATIC)
        set(CPPAN_BUILD_SHARED_LIBS 0)
    else()
        set(CPPAN_BUILD_SHARED_LIBS 1)
    endif()
    add_subdirectory(.cppan)
endif()

after this I tried to build the library with this command :

vcpkg install tesseract[core]:arm-android

the build process exits due to error near the end the libtesseract.a library is built but not the binary tesseract

there is a long log in install-arm-android-rel-out.log and this is the error at the end :

[240/242] cmd.exe /C "cd . && E:\programs\vcpkg\downloads\tools\cmake-3.14.0-windows\cmake-3.14.0-win32-x86\bin\cmake.exe -E remove libtesseract.a && E:\programs\ndk\android-ndk-r20\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ar.exe qc libtesseract.a  @CMakeFiles\libtesseract.rsp && E:\programs\ndk\android-ndk-r20\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-ranlib.exe libtesseract.a && cd ."
[241/242] cmd.exe /C "cd . && E:\programs\ndk\android-ndk-r20\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=armv7-none-linux-androideabi21 --gcc-toolchain=E:/programs/ndk/android-ndk-r20/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=E:/programs/ndk/android-ndk-r20/toolchains/llvm/prebuilt/windows-x86_64/sysroot  -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -march=armv7-a -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -frtti -fexceptions  --std=c++11 -Oz -DNDEBUG  -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack -Wl,--gc-sections CMakeFiles/tesseract.dir/src/api/tesseractmain.cpp.o  -o bin\tesseract  libtesseract.a -lpthread E:/programs/vcpkg/installed/arm-android/lib/libleptonica.a E:/programs/vcpkg/installed/arm-android/lib/libgif.a E:/programs/vcpkg/installed/arm-android/lib/libjpeg.a E:/programs/vcpkg/installed/arm-android/share/png/../../lib/libpng16.a E:/programs/vcpkg/installed/arm-android/lib/libtiff.a E:/programs/vcpkg/installed/arm-android/lib/liblzma.a E:/programs/vcpkg/installed/arm-android/lib/libjpeg.a E:/programs/vcpkg/installed/arm-android/share/png/../../lib/libpng16.a E:/programs/vcpkg/installed/arm-android/lib/libtiff.a E:/programs/vcpkg/installed/arm-android/lib/liblzma.a E:/programs/vcpkg/installed/arm-android/lib/libz.a -lm E:/programs/vcpkg/installed/arm-android/lib/libz.a -lm -latomic -lm && cd ."
FAILED: bin/tesseract 
cmd.exe /C "cd . && E:\programs\ndk\android-ndk-r20\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=armv7-none-linux-androideabi21 --gcc-toolchain=E:/programs/ndk/android-ndk-r20/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=E:/programs/ndk/android-ndk-r20/toolchains/llvm/prebuilt/windows-x86_64/sysroot  -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -march=armv7-a -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -frtti -fexceptions  --std=c++11 -Oz -DNDEBUG  -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack -Wl,--gc-sections CMakeFiles/tesseract.dir/src/api/tesseractmain.cpp.o  -o bin\tesseract  libtesseract.a -lpthread E:/programs/vcpkg/installed/arm-android/lib/libleptonica.a E:/programs/vcpkg/installed/arm-android/lib/libgif.a E:/programs/vcpkg/installed/arm-android/lib/libjpeg.a E:/programs/vcpkg/installed/arm-android/share/png/../../lib/libpng16.a E:/programs/vcpkg/installed/arm-android/lib/libtiff.a E:/programs/vcpkg/installed/arm-android/lib/liblzma.a E:/programs/vcpkg/installed/arm-android/lib/libjpeg.a E:/programs/vcpkg/installed/arm-android/share/png/../../lib/libpng16.a E:/programs/vcpkg/installed/arm-android/lib/libtiff.a E:/programs/vcpkg/installed/arm-android/lib/liblzma.a E:/programs/vcpkg/installed/arm-android/lib/libz.a -lm E:/programs/vcpkg/installed/arm-android/lib/libz.a -lm -latomic -lm && cd ."
E:/programs/ndk/android-ndk-r20/toolchains/llvm/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: error: cannot find -lpthread
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

as you can see the linker can't find pthread !

this is my arm-android.cmake used by vcpkg :

set(VCPKG_TARGET_ARCHITECTURE arm)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE static)

set(VCPKG_CMAKE_SYSTEM_NAME Android)
set(VCPKG_BUILD_TYPE release)

and I set these variables :

set "ANDROID_NDK=E:\programs\ndk\android-ndk-r20\"
set "ANDROID_NDK_HOME=E:\programs\ndk\android-ndk-r20\"

You don't need glob. After all, you are building for a mobile device, where you won't perform training. The file fileio.cpp that refers to glob, is only used in training.

Android NDK is special in that it does not have libpthread, the pthread implementation is inside libc. The easy hack is to copy libc.a to libpthread.a, or create an empty libpthread.a with ar command.

You may find the preconfigured docker build environment helpful. If you prefer an ndk-build version, fully integrated into Android Studio, have a look at my fork: https://github.com/alexcohn/tess-two .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM