pnggroup / libpng

LIBPNG: Portable Network Graphics support, official libpng repository
http://libpng.sf.net
Other
1.29k stars 625 forks source link

Android Studio NDK r26b failed to compile #504

Closed Haruma-VN closed 11 months ago

Haruma-VN commented 11 months ago

I am using CMAKE with libpng to support cross platform, however when tried to compile the shared library to the Android platform an error occured. image

Here is my CMakeLists.txt

project(
    libpng
    VERSION 1.6.37
    HOMEPAGE_URL http://www.libpng.org/pub/png/libpng.html
    LANGUAGES C
)

if (MSVC)
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zi")
else ()
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
endif ()

add_library(
    ${PROJECT_NAME} STATIC
    ./png.h
    ./pngconf.h
    ./pnglibconf.h
    ./pngpriv.h
    ./pngdebug.h
    ./pnginfo.h
    ./pngstruct.h
    ./png.c
    ./pngerror.c
    ./pngget.c
    ./pngmem.c
    ./pngpread.c
    ./pngread.c
    ./pngrio.c
    ./pngrtran.c
    ./pngrutil.c
    ./pngset.c
    ./pngtrans.c
    ./pngwio.c
    ./pngwrite.c
    ./pngwtran.c
    ./pngwutil.c
)

target_include_directories(
    ${PROJECT_NAME} PUBLIC
    ../zlib
)

target_link_libraries(
    ${PROJECT_NAME} PRIVATE
    zlib
)

set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON)

Here is the error:

ld.lld: error: undefined symbol: png_riffle_palette_neon
>>> referenced by pngrtran.c:4782 (D:/Code/Sen.Environment/Kernel/dependencies/libpng/pngrtran.c:4782)
>>>               pngrtran.c.o:(png_do_read_transformations) in archive dependencies/libpng/liblibpng.a

ld.lld: error: undefined symbol: png_do_expand_palette_rgba8_neon
>>> referenced by pngrtran.c:4323 (D:/Code/Sen.Environment/Kernel/dependencies/libpng/pngrtran.c:4323)
>>>               pngrtran.c.o:(png_do_expand_palette) in archive dependencies/libpng/liblibpng.a

ld.lld: error: undefined symbol: png_do_expand_palette_rgb8_neon
>>> referenced by pngrtran.c:4354 (D:/Code/Sen.Environment/Kernel/dependencies/libpng/pngrtran.c:4354)
>>>               pngrtran.c.o:(png_do_expand_palette) in archive dependencies/libpng/liblibpng.a

ld.lld: error: undefined symbol: png_init_filter_functions_neon
>>> referenced by pngrutil.c:4127 (D:/Code/Sen.Environment/Kernel/dependencies/libpng/pngrutil.c:4127)
>>>               pngrutil.c.o:(png_init_filter_functions) in archive dependencies/libpng/liblibpng.a
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

I would like some help to compile this library for my project, glad if someone helped.

ctruta commented 11 months ago

You should either include the machine-specific subdirectories (arm/, intel/, etc.) depending on your target platform, or disable the machine-specific code via macros, as it is done, for example, in scripts/makefile.clang.

I think should also work:

CMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS} -DPNG_ARM_NEON_OPT=0 -DPNG_MIPS_MSA_OPT=0 -DPNG_POWERPC_VSX_OPT=0 -DPNG_INTEL_SSE_OPT=0"
Haruma-VN commented 11 months ago

It appears that when I add this to my CMakeLists it worked:

if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm")
    target_compile_definitions(${PROJECT_NAME} PUBLIC PNG_ARM_NEON_OPT=0)
endif()

But still, thank you for your kind responses.