webmproject / sjpeg

SimpleJPEG: simple jpeg encoder
Apache License 2.0
72 stars 13 forks source link

build for Android failed #120

Closed leleliu008 closed 1 year ago

leleliu008 commented 1 year ago

reported esser messages:

ld: error: undefined symbol: sjpeg::EncoderParam::ResetMetadata()
>>> referenced by utils.cc:514 (/home/leleliu008/.ndk-pkg/run/2308279/sjpeg/src/examples/utils.cc:514)
>>>               CMakeFiles/sjpeg-utils.dir/examples/utils.cc.o:(ReadJPEG(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&, int*, int*, sjpeg::EncoderParam*))
>>> referenced by utils.cc:320 (/home/leleliu008/.ndk-pkg/run/2308279/sjpeg/src/examples/utils.cc:320)
>>>               CMakeFiles/sjpeg-utils.dir/examples/utils.cc.o:(ReadJPEG(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&, int*, int*, sjpeg::EncoderParam*))
>>> referenced by utils.cc:745 (/home/leleliu008/.ndk-pkg/run/2308279/sjpeg/src/examples/utils.cc:745)
>>>               CMakeFiles/sjpeg-utils.dir/examples/utils.cc.o:(ReadPNG(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&, int*, int*, sjpeg::EncoderParam*))
>>> referenced 3 more times
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

workaroud:

sed -i '133c target_link_libraries(sjpeg-utils sjpeg)' CMakeLists.txt
jzern commented 1 year ago

cc @skal65535

Thanks for the report. The dependency looks correct. Alternatively the order of the libraries in the target_link_libraries() calls could be swapped.

How are you configuring the project? I don't see an issue using .. -DCMAKE_TOOLCHAIN_FILE=../cmake/android.cmake -DSJPEG_ANDROID_NDK_PATH=<path-to>/android-ndk-r25b.

leleliu008 commented 1 year ago

@jzern You didn't encounter this because you didn't install the libpng and libjpeg-turbo therefore cmake didn't find them, which in turn SJPEG_HAVE_JPEG and SJPEG_HAVE_PNG macro were not defined, ReadJPEG and ReadPNG didn't compile.

my config: https://github.com/leleliu008/ndk-pkg-formula-repository-offical-core/blob/master/formula/sjpeg.yml

leleliu008 commented 1 year ago

reproduce steps:

git clone --depth 1 https://github.com/webmproject/sjpeg
cd sjpeg
cmake \
    -Wno-dev \
    -DCMAKE_EXPORT_COMPILE_COMMANDS=OFF \
    -DBUILD_TESTING=OFF \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_VERBOSE_MAKEFILE=ON \
    -DCMAKE_COLOR_MAKEFILE=ON \
    -DCMAKE_TOOLCHAIN_FILE='/home/leleliu008/.uppm/installed/android-ndk-r25c/build/cmake/android.toolchain.cmake' \
    -DCMAKE_INSTALL_PREFIX="$PWD/out" \
    -DANDROID_TOOLCHAIN=clang \
    -DANDROID_ABI=arm64-v8a \
    -DANDROID_ARM_NEON=TRUE \
    -DANDROID_STL=c++_shared \
    -DANDROID_PLATFORM=21 \
    -S . \
    -B build.d \
    -DBUILD_SHARED_LIBS=ON \
    -DSJPEG_BUILD_EXAMPLES=ON \
    -DSJPEG_ANDROID_NDK_PATH=/home/leleliu008/.uppm/installed/android-ndk-r25c
ld: error: undefined symbol: sjpeg::EncoderParam::ResetMetadata()
>>> referenced by utils.cc:877 (/home/leleliu008/sjpeg/examples/utils.cc:877)
>>>               CMakeFiles/sjpeg-utils.dir/examples/utils.cc.o:(ReadPPM(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&, int*, int*, sjpeg::EncoderParam*))
>>> referenced by utils.cc:922 (/home/leleliu008/sjpeg/examples/utils.cc:922)
>>>               CMakeFiles/sjpeg-utils.dir/examples/utils.cc.o:(ReadFail(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&, int*, int*, sjpeg::EncoderParam*))
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
gmake[2]: *** [CMakeFiles/sjpeg-utils.dir/build.make:100: libsjpeg-utils.so] Error 1
gmake[2]: Leaving directory '/home/leleliu008/sjpeg/build.d'
gmake[1]: *** [CMakeFiles/Makefile2:146: CMakeFiles/sjpeg-utils.dir/all] Error 2
gmake[1]: Leaving directory '/home/leleliu008/sjpeg/build.d'
jzern commented 1 year ago

@jzern You didn't encounter this because you didn't install the libpng and libjpeg-turbo therefore cmake didn't find them, which in turn SJPEG_HAVE_JPEG and SJPEG_HAVE_PNG macro were not defined, ReadJPEG and ReadPNG didn't compile.

You're right, I wasn't paying attention the source of the link error. In other builds, specifying -Wl,--no-undefined is enough to reproduce the issue.