[英]build libpng for android using cmake fail
I am trying to build libpng 1.6.34 to use on my android project.我正在尝试构建 libpng 1.6.34 以在我的 android 项目上使用。 I also try to use cmake
我也尝试使用 cmake
this is build_libpng.sh file这是 build_libpng.sh 文件
export CMAKE_SYSTEM_NAME=Android
export CMAKE_BUILD_TYPE=Debug
export CMAKE_TOOLCHAIN_FILE=~/android-sdk/ndk-bundle/build/cmake/android.toolchain.cmake
export CMAKE_LIBRARY_OUTPUT_DIRECTORY=obj/armeabi-v7a
export ANDROID_ABI=armeabi-v7a
export ANDROID_PLATFORM=android-15
export ANDROID_NDK=~/android-sdk/ndk-bundle
export CMAKE_CXX_FLAGS=-frtti -fexceptions
export ZLIB_INCLUDE_DIR=./zlib.1.2.11
export ZLIB_LIBRARY=./zlib.1.2.11
~/android-sdk/cmake/3.6.4111459/bin/cmake -G"Android Gradle - Unix Makefiles" ./lpng1634/CMakeLists.txt
after execute build_libpng.sh and call make this is the log.执行 build_libpng.sh 并调用 make 后,这是日志。
Scanning dependencies of target genfiles
[ 0%] Built target genfiles
Scanning dependencies of target png
[ 2%] Building C object CMakeFiles/png.dir/png.c.o
[ 5%] Building C object CMakeFiles/png.dir/pngerror.c.o
[ 8%] Building C object CMakeFiles/png.dir/pngget.c.o
[ 11%] Building C object CMakeFiles/png.dir/pngmem.c.o
[ 13%] Building C object CMakeFiles/png.dir/pngpread.c.o
[ 16%] Building C object CMakeFiles/png.dir/pngread.c.o
[ 19%] Building C object CMakeFiles/png.dir/pngrio.c.o
[ 22%] Building C object CMakeFiles/png.dir/pngrtran.c.o
[ 25%] Building C object CMakeFiles/png.dir/pngrutil.c.o
[ 27%] Building C object CMakeFiles/png.dir/pngset.c.o
[ 30%] Building C object CMakeFiles/png.dir/pngtrans.c.o
[ 33%] Building C object CMakeFiles/png.dir/pngwio.c.o
[ 36%] Building C object CMakeFiles/png.dir/pngwrite.c.o
[ 38%] Building C object CMakeFiles/png.dir/pngwtran.c.o
[ 41%] Building C object CMakeFiles/png.dir/pngwutil.c.o
[ 44%] Linking C shared library obj/armeabi-v7a/libpng16d.so
[]/android-sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot open [...]/third_party/lpng1634/libpng.vers: No such file or directory
[...]/android-sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: fatal error: unable to parse version script file [...]/third_party/lpng1634/libpng.vers
clang: error: linker command failed with exit code 1 (use -v to see invocation)
CMakeFiles/png.dir/build.make:459: recipe for target 'obj/armeabi-v7a/libpng16d.so' failed
make[2]: *** [obj/armeabi-v7a/libpng16d.so] Error 1
CMakeFiles/Makefile2:99: recipe for target 'CMakeFiles/png.dir/all' failed
make[1]: *** [CMakeFiles/png.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
I read the lpng1634/CMakeLists.txt has some I dont realy understand.我读了 lpng1634/CMakeLists.txt 有一些我不太明白。
At this part在这部分
if(NOT AWK OR ANDROID)
# No awk available to generate sources; use pre-built pnglibconf.h
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.h.prebuilt
${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h)
add_custom_target(genfiles) # Dummy
else()
... code for generating libpng.vers here
endif(NOT AWK OR ANDROID)
but this part但这部分
if(PNG_SHARED)
add_library(png SHARED ${libpng_sources})
set(PNG_LIB_TARGETS png)
set_target_properties(png PROPERTIES OUTPUT_NAME ${PNG_LIB_NAME})
add_dependencies(png genfiles)
if(MSVC)
# msvc does not append 'lib' - do it here to have consistent name
set_target_properties(png PROPERTIES PREFIX "lib")
set_target_properties(png PROPERTIES IMPORT_PREFIX "lib")
endif()
target_link_libraries(png ${ZLIB_LIBRARY} ${M_LIBRARY})
if(UNIX AND AWK)
if(HAVE_LD_VERSION_SCRIPT)
set_target_properties(png PROPERTIES LINK_FLAGS
"-Wl,--version-script='${CMAKE_CURRENT_BINARY_DIR}/libpng.vers'")
elseif(HAVE_SOLARIS_LD_VERSION_SCRIPT)
set_target_properties(png PROPERTIES LINK_FLAGS
"-Wl,-M -Wl,'${CMAKE_CURRENT_BINARY_DIR}/libpng.vers'")
endif()
endif()
endif()
using libpng.vers that is the cause of my problem i guess.使用 libpng.vers 那是我的问题的原因我猜。
Did I config something wrong?我配置错了吗? can you help?
你能帮我吗?
Use the -DHAVE_LD_VERSION_SCRIPT=OFF
option, disable building the shared library -DPNG_SHARED=OFF
or dig deep into the cmake code upstream使用
-DHAVE_LD_VERSION_SCRIPT=OFF
选项,禁用构建共享库-DPNG_SHARED=OFF
或深入挖掘上游的 cmake 代码
cmake -DHAVE_LD_VERSION_SCRIPT=OFF ./lpng1634
... just as far as I followed up on it ... ......就我跟进而言......
When building a .so file, libpng wants to version it.在构建 .so 文件时,libpng 想要对其进行版本控制。 For this it pregenerates a number of files, among them
libpng.vers
.为此,它
libpng.vers
生成了许多文件,其中包括libpng.vers
。 If ANDROID
is defined (or AWK
is not available) it skips generating the libpng.vers
file.如果定义了
ANDROID
(或AWK
不可用),它会跳过生成libpng.vers
文件。 Even if it was not generated, it will still tell the linker to use it and fails (leading to the error you posted).即使它没有生成,它仍然会告诉链接器使用它并失败(导致您发布的错误)。 You can trick cmake into skipping the versioning by specifying
-DHAVE_LD_VERSION_SCRIPT=OFF
.您可以通过指定
-DHAVE_LD_VERSION_SCRIPT=OFF
来欺骗 cmake 跳过版本控制。
One might ask now why it does not just generate this .vers
file, so everything works.现在有人可能会问为什么它不只是生成这个
.vers
文件,所以一切正常。 It looks like the generator uses a handcrafted compiler invocation which is not super solid and fails when cross compiling for some architectures.看起来生成器使用手工编译的编译器调用,它不是超级可靠,并且在为某些架构进行交叉编译时会失败。 The right choice would likely be digging into these scripts and fixing things up there.
正确的选择可能是深入研究这些脚本并修复那里的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.