libpng icon indicating copy to clipboard operation
libpng copied to clipboard

Cross Compilation for Android while having AWK seems to fail

Open strattist opened this issue 6 years ago • 5 comments

Using the git as an external module built with CMake there is some strange condition in the CMakeLists.txt (starting line 261):

find_program(AWK NAMES gawk awk)

include_directories(${CMAKE_CURRENT_BINARY_DIR})

if(NOT AWK OR ANDROID)
  # Compilation for Android
else()
  # Any other compilation 
endif()

Followed by (starting line 519):

if(PNG_SHARED)
  # Some stuff

  # No more Android related condition while libpng.vers is not generated if Android compilation
  if(UNIX AND AWK) 
    if(HAVE_LD_VERSION_SCRIPT)
      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()

I don't know if I use it correctly. Maybe I shouldn't compile libpng as a shared library for Android ? I found those conditions strange anyway so I just wanted to put my remark here.

strattist avatar Jul 13 '18 12:07 strattist

I had the same issue trying to build libpng for Android using CMake, I get the following error:

[ 34%] Linking C shared library libpng16.so
/home/markand/android/ndk-bundle/toolchains/x86-4.9/prebuilt/linux-x86_64/lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/bin/ld: error: cannot open /tmp/libpng-1.6.35/build/libpng.vers: No such file or directory
/home/markand/android/ndk-bundle/toolchains/x86-4.9/prebuilt/linux-x86_64/lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/bin/ld: fatal error: unable to parse version script file /tmp/libpng-1.6.35/build/libpng.vers
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [CMakeFiles/png.dir/build.make:296: libpng16.so] Error 1
make[1]: *** [CMakeFiles/Makefile2:396: CMakeFiles/png.dir/all] Error 2
make: *** [Makefile:141: all] Error 2

I think it's related. Perhaps for android we could just disable the condition?

markand avatar Oct 14 '18 15:10 markand

I've discovered this issue when trying to cross-compile libpng using Conan package manager: https://github.com/conan-io/conan-center-index/issues/8003

Matthias on Stackoverflow found solution - use -DHAVE_LD_VERSION_SCRIPT=OFF: https://stackoverflow.com/a/62541328

Not sure if this is "correct" or is it "workaround", but library builds. Maybe it's worth disabling that feature on Android by default?

Talkless avatar Mar 18 '22 06:03 Talkless

Hi. This is solved? I have the same problem :(

paulocoutinhox avatar Nov 17 '22 19:11 paulocoutinhox

I thought the problem was solved in libpng-1.6.38. Could you please double-check and make sure that you are not still using 1.6.37? BTW, libpng-1.6.39 is already out.

ctruta avatar Nov 21 '22 15:11 ctruta

-DHAVE_LD_VERSION_SCRIPT=OFF is a high-level fix. Much better is there: #254 but still not ideal. Will try to understand why this nasty symbol SYMBOL_PREFIXname is going to be generated at all....

icegood avatar Jul 21 '24 21:07 icegood