jasper-software / jasper

Official Repository for the JasPer Image Coding Toolkit
http://www.ece.uvic.ca/~mdadams/jasper
Other
217 stars 103 forks source link

build failed on glibc based GNU/Linux #379

Closed leleliu008 closed 4 months ago

leleliu008 commented 4 months ago

source code

https://github.com/jasper-software/jasper/releases/download/version-4.2.2/jasper-4.2.2.tar.gz

my build machine os information

PRETTY_NAME="Ubuntu 23.10"
NAME="Ubuntu"
VERSION_ID="23.10"
VERSION="23.10 (Mantic Minotaur)"
VERSION_CODENAME=mantic
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=mantic
LOGO=ubuntu-logo

reported error messages

cc -I/github/home/.ppkg/run/3662/jasper/include -I/github/home/.ppkg/installed/linux-glibc-x86_64/libjpeg-turbo/include  -DNDEBUG  -fPIC -fno-common -Os  -pedantic -O3 -L/github/home/.ppkg/run/3662/jasper/lib -L/github/home/.ppkg/installed/linux-glibc-x86_64/libjpeg-turbo/lib -Wl,-rpath,/github/home/.ppkg/installed/linux-glibc-x86_64/libjpeg-turbo/lib -Wl,--as-needed -Wl,-z,muldefs -Wl,--allow-multiple-definition -Wl,-S src/app/CMakeFiles/imginfo.dir/imginfo.c.o -o src/app/imginfo  src/libjasper/libjasper.a  /github/home/.ppkg/installed/linux-glibc-x86_64/libjpeg-turbo/lib/libjpeg.a  /usr/lib/x86_64-linux-gnu/libm.a  /usr/lib/x86_64-linux-gnu/libpthread.a && :
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libm-2.35.a(e_pow.o): warning: relocation against `_dl_x86_cpu_features' in read-only section `.text'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libm-2.35.a(e_pow.o): in function `__ieee754_pow_ifunc':
(.text+0x746): undefined reference to `_dl_x86_cpu_features'
/usr/bin/ld: (.text+0x74f): undefined reference to `_dl_x86_cpu_features'
/usr/bin/ld: (.text+0x75f): undefined reference to `_dl_x86_cpu_features'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status

cmake configure command

cmake \
       -DCMAKE_PROJECT_INCLUDE=$PWD/project-after.cmake \
       -DCMAKE_VERBOSE_MAKEFILE=ON \
       -DCMAKE_COLOR_MAKEFILE=ON \
       -DBUILD_TESTING=OFF \
       -DALLOW_IN_SOURCE_BUILD=ON \
       -DJAS_ENABLE_DOC=OFF \
       -DJAS_ENABLE_SHARED=OFF \
       -DJAS_ENABLE_PROGRAMS=ON \
       -DJAS_STDC_VERSION=201710L \
       -S .\
       -B build.d

project-after.cmake

set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" ".so")

reason

https://sourceware.org/bugzilla/show_bug.cgi?id=21264

my fix

--- CMakeLists.txt  2024-03-12 04:35:04.000000000 +0800
+++ CMakeLists.txt.bak  2024-03-18 10:35:34.209569491 +0800
@@ -575,7 +575,9 @@
 ################################################################################

 find_library(PTHREAD_LIBRARY pthread)
-if(NOT PTHREAD_LIBRARY)
+if(PTHREAD_LIBRARY)
+   set(PTHREAD_LIBRARY "-lpthread")
+else()
    set(PTHREAD_LIBRARY "")
 endif()

@@ -789,7 +791,9 @@
 ################################################################################

 find_library(MATH_LIBRARY m)
-if(NOT MATH_LIBRARY)
+if(MATH_LIBRARY)
+   set(MATH_LIBRARY "-lm")
+else()
    set(MATH_LIBRARY "")
 endif()
mdadams commented 4 months ago

@leleliu008 First, please always submit proposed code changes in the form of a pull request. There are many reasons why this is beneficial (e.g., being able to automatically run CI test cases on the modified code). Second, your change looks non-portable and I think that it may break things on some systems. CMake will set PTHREAD_LIBRARY to the correct library value for the platform in question. We should not really override it. Also, what is in the file project-after.cmake? This information seems to be missing.

leleliu008 commented 4 months ago

project-after.cmake file content is following:

set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" ".so")
leleliu008 commented 4 months ago

I change the default behaver, I perfer to use static library, that code tell cmake find static library first. On glibc based GNU/Linux, creating a dynamically linked executable cannot link static library of libm

mdadams commented 4 months ago

@leleliu008 I'm sorry. Somehow I missed the contents of the file from your original post. I am unclear why you want .so library suffixes when building JasPer as a static library. I am not sure if I understood the problem report link that you sent but it seems that there is an issue with mixing shared and static libraries? Is this correct? Some commentary would be helpful. Also, what specific platform are you using (e.g., OS, version, architecture, etc.)? Do you have this problem if you build JasPer as a shared library? I am also curious why you are using -DJAS_STDC_VERSION. I think that this should only be needed when crosscompiling.

leleliu008 commented 4 months ago

https://sourceware.org/bugzilla/show_bug.cgi?id=21264 this link tell us why this problem has happened. It says on glibc based GNU/Linux, creating a dynamically linked executable cannot link libm.a , but find_library(MATH_LIBRARY m) got /usr/lib/x86_64-linux-gnu/libm-2.35.a because I set set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" ".so"), that means I changed the default behaver, I perfer to use static library, that code tell cmake find static library first.

I am also curious why you are using -DJAS_STDC_VERSION. I think that this should only be needed when crosscompiling.

I wrote a package manager, my package manager can do both native build and cross build.

leleliu008 commented 4 months ago

what specific platform are you using (e.g., OS, version, architecture, etc.)?

my build machine os is ubuntu-22.04 x86_64, a glibc base GNU/Linux, ubuntu

leleliu008 commented 4 months ago

I am unclear why you want .so library suffixes when building JasPer as a static library.

This problem happened when building src/app/imginfo, not when build libjasper

leleliu008 commented 4 months ago

Screenshot from 2024-03-18 12-03-07

maybe reported error messages are too long? I give you a screenshot, this may looks clear.

mdadams commented 4 months ago

The problem appears to be that you are trying to link with a mix of static and shared libraries that are not compatible. In particular, it appears that you are using a shared C library but a static math library (libm). The problem that you are experiencing is caused by your project-after.cmake, however. I can reproduce your problem in Ubuntu 23.10, which you are using above, if I use your project-after.cmake file. If I do not use the project-after.cmake file, everything works fine for me, even when JasPer is built with JAS_ENABLED_SHARED=0. So, in this sense, there is no bug in JasPer. The problem is that you are effectively modifying that build of jasPer via the CMAKE_PROJECT_INCLUDE setting (and your project-after.cmake file), and then blaming JasPer when this breaks things. But it is not really JasPer's fault. You should not modify the build in this way, as it will lead to the types of problems that you are seeing.

leleliu008 commented 4 months ago

Thank you for your comments. I will close this then.