gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 03:15:07 32 4
gpt4 key购买 nike

我正在尝试使用 vcpkg 和 ndk r20 为 android arm 构建 tesseract我必须编辑 CMakeLists.txt 并添加 glob.c 和 glob.h,因为它们不在 ndk 中

我还让 fileio.cpp 包含了 glob.h

然后我不得不绕过 pkg-config 因为 ndk 没有它我替换这个:

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()

用这个:

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()

在此之后,我尝试使用此命令构建库:

vcpkg install tesseract[core]:arm-android

构建过程由于接近尾声的错误而退出构建了 libtesseract.a 库,但未构建二进制 tesseract

install-arm-android-rel-out.log 中有很长的日志,这是最后的错误:

[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.

如您所见,链接器找不到 pthread!

这是 vcpkg 使用的我的 arm-android.cmake :

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)

我设置了这些变量:

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

最佳答案

你不需要 glob。毕竟,您是为移动设备构建的,您不会在其中执行训练。引用 glob 的文件 fileio.cpp 仅在训练中使用。

Android NDK比较特殊的是它没有libpthread,pthread的实现在libc里面。简单的破解方法是将 libc.a 复制到 libpthread.a,或者使用 ar 命令创建一个空的 libpthread.a。

您可能会发现预配置的 docker build environment有帮助。如果您更喜欢完全集成到 Android Studio 中的 ndk-build 版本,请查看我的 fork :https://github.com/alexcohn/tess-two .

关于android - ndk r20 ld : ld: error: cannot find -lpthread,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57289494/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com