xinxinlx / openjpeg

Automatically exported from code.google.com/p/openjpeg
Other
0 stars 0 forks source link

pkg-config file should list Libs.private with -lm for static linking #223

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Build openjpeg with BUILD_SHARED_LIBS=OFF
2. link against static openjpeg with gcc --static $(pkg-config --libs --static 
libopenjp2)
3. libopenjp2.a(mct.c.o) uses sqrt, lrintf and floor from -lm which is not 
listed in the pkg-config output. Linking fails.

As seen below, the -lm previous to -lopenjp2 is added by another dependency, 
but ignored for openjp2 due the -Wl,--as-needed, which is a common LDFLAGS 
element.

What is the expected output? What do you see instead?
Add a Libs.private line to your .pc file to fix it.

--- /usr/lib64/pkgconfig/libopenjp2.pc.orig
+++ /usr/lib64/pkgconfig/libopenjp2.pc
@@ -10,4 +10,5 @@
 URL: http://www.openjpeg.org/
 Version: 2.0.0
 Libs: -L${libdir} -lopenjp2
+Libs.private: -L-L${libdir} -lopenjp2 -lm
 Cflags: -I${includedir}

What version of the product are you using? On what operating system?
Openjpeg 2.0.0 and CVS trunk on Gentoo Linux, gcc-4.8.1 

Please provide any additional information below.

x86_64-pc-linux-gnu-gcc -Wl,--hash-style=gnu -Wl,-O1 -Wl,--as-needed -o 
build/debug/mupdf build/debug/x11_main.o build/debug/x11_image.o 
build/debug/pdfapp.o build/debug/libfitz.a -static -lm -lfreetype -lz -lbz2  
-ljbig2dec -ljpeg -lopenjp2  -lcrypto -ldl -lz  -lz -lXext -lX11 -lpthread 
-lxcb -lXau -lXdmcp
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.1/../../../../lib64/libcrypto.a(dso_dlfcn.o
): In function `dlfcn_globallookup':
(.text+0x11): warning: Using 'dlopen' in statically linked applications 
requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.1/../../../../lib64/libX11.a(xim_trans.o): 
In function `_XimXTransSocketINETConnect':
(.text+0xda6): warning: Using 'getaddrinfo' in statically linked applications 
requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.1/../../../../lib64/libopenjp2.a(mct.c.o): 
In function `opj_calculate_norms':
(.text+0x6b2): undefined reference to `sqrt'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.1/../../../../lib64/libopenjp2.a(tcd.c.o): 
In function `opj_tcd_decode_tile':
(.text+0x35b7): undefined reference to `lrintf'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.1/../../../../lib64/libopenjp2.a(dwt.c.o): 
In function `opj_dwt_calc_explicit_stepsizes':
(.text+0x1a8e): undefined reference to `floor'

Original issue reported on code.google.com by michaelb...@googlemail.com on 8 Jun 2013 at 10:11

GoogleCodeExporter commented 9 years ago
Version 2.0.0 patched with 
http://code.google.com/p/openjpeg/source/detail?r=2250
And the added line has one extra -L, the correct patch/path for the source is

--- openjpeg-2.0.0/src/lib/openjp2/libopenjp2.pc.cmake.in.orig
+++ openjpeg-2.0.0/src/lib/openjp2/libopenjp2.pc.cmake.in
@@ -10,4 +10,5 @@
 URL: http://www.openjpeg.org/
 Version: @OPENJPEG_VERSION@
 Libs: -L${libdir} -lopenjp2
+Libs.private: -L${libdir} -lopenjp2 -lm
 Cflags: -I${includedir}

Original comment by michaelb...@googlemail.com on 8 Jun 2013 at 10:19

GoogleCodeExporter commented 9 years ago
'man pgk-config':

       Libs.private:
              This line should list any private  libraries  in  use.   Private
              libraries  are  libraries  which  are  not  exposed through your
              library, but are needed in the case of static linking. This dif-
              fers  from Requires.private in that it references libraries that
              do not have package files installed.

'-lopenjp2' is not an additional library, but '-lm' is.

winfried

Original comment by szukw...@arcor.de on 11 Jul 2013 at 12:10

GoogleCodeExporter commented 9 years ago
Would it make sense to apply only the following patch then ?

--- openjpeg-2.0.0/src/lib/openjp2/libopenjp2.pc.cmake.in.orig
+++ openjpeg-2.0.0/src/lib/openjp2/libopenjp2.pc.cmake.in
@@ -10,4 +10,5 @@
 URL: http://www.openjpeg.org/
 Version: @OPENJPEG_VERSION@
 Libs: -L${libdir} -lopenjp2
+Libs.private: -L${libdir} -lm
 Cflags: -I${includedir}

Original comment by mathieu.malaterre on 24 Feb 2014 at 9:24

GoogleCodeExporter commented 9 years ago
Libs.private is for UNIX only. And UNIX usually knows where '-lm' is located.
'${libdir}' is the installation path of 'libopenjp2':
This means:

Libs.private: -lm

is enough.

winfried

Original comment by szukw...@gmail.com on 24 Feb 2014 at 5:19

GoogleCodeExporter commented 9 years ago
Ok. Fixed in r2404. Closing

Original comment by mathieu.malaterre on 24 Feb 2014 at 5:24

GoogleCodeExporter commented 9 years ago

Original comment by mathieu.malaterre on 28 Feb 2014 at 8:32