Skip to contentSkip to conversation

yajl: fix build with uClibc

PATCH New Vicente Olivert Riera 3 participants 3 messages Apr 20, 2016 – Apr 22, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 yajl: fix build with uClibc

The failure looks like this:

../yajl-2.1.0/lib/libyajl.so.2.1.0: undefined reference to __isinf' ../yajl-2.1.0/lib/libyajl.so.2.1.0: undefined reference to __isnan'

We already have a patch (0001) which should fix this problem, however, as stated here [1], it doesn't work when cross compiling.

To fix the problem we add -lm to CFLAGS when building with uClibc.

Fixes:

http://autobuild.buildroot.net/results/308/30892ffb298acc2334f8c694038c420120fe43b9/

1: https://github.com/lloyd/yajl/issues/58#issuecomment-15683796

---
 package/yajl/yajl.mk | 4 ++++
 1 file changed, 4 insertions(+)
package/yajl/yajl.mk +4 -0
index 7770e86..145bf2c 100644
@@ -11,4 +11,8 @@ YAJL_LICENSE = ISC
 YAJL_LICENSE_FILES = COPYING
 YAJL_PATCH = https://github.com/vriera/yajl/commit/6d09f11b8fd358cab0e31b965327e64a599f9ce9.patch
 
+ifeq ($(BR2_TOOLCHAIN_USES_UCLIBC),y)
+YAJL_CONF_OPTS += -DCMAKE_C_FLAGS="$(TARGET_CFLAGS) -lm"
+endif
+
 $(eval $(cmake-package))
Signature · 1 line
2.7.3
#1 lore raw

PATCH 1/1 yajl: fix build with uClibc

Hi Vicente,

Quoted 36 lines · Vicente Olivert Riera

The failure looks like this:

../yajl-2.1.0/lib/libyajl.so.2.1.0: undefined reference to __isinf' ../yajl-2.1.0/lib/libyajl.so.2.1.0: undefined reference to __isnan'

We already have a patch (0001) which should fix this problem, however,
as stated here [1], it doesn't work when cross compiling.

To fix the problem we add -lm to CFLAGS when building with uClibc.

Fixes:

? http://autobuild.buildroot.net/results/308/30892ffb298acc2334f8c694
038c420120fe43b9/

1: https://github.com/lloyd/yajl/issues/58#issuecomment-15683796

---
?package/yajl/yajl.mk | 4 ++++
?1 file changed, 4 insertions(+)

package/yajl/yajl.mk +0 -0
index 7770e86..145bf2c 100644
@@ -11,4 +11,8 @@ YAJL_LICENSE = ISC

?YAJL_LICENSE_FILES = COPYING
?YAJL_PATCH = https://github.com/vriera/yajl/commit/6d09f11b8fd358cab
0e31b965327e64a599f9ce9.patch
?

package/yajl/yajl.mk +4 -0
+ifeq ($(BR2_TOOLCHAIN_USES_UCLIBC),y)
+YAJL_CONF_OPTS += -DCMAKE_C_FLAGS="$(TARGET_CFLAGS) -lm"
+endif
+
Quoted 1 line

?$(eval $(cmake-package))

For the record, Bernd Kuhls proposed a patch [1] to fix this issue, too.

The patch [2] in commit?3cfd8bf15cd8b80215bb70db28e065ff0b80437b fixed an issue, where the executables build in yajl, like 'parse_config', are linked against the static yajl library, even in a shared context.

Unfortunatly, the submitter (me) of this patch did not test with the uClibc based toolchain, but only for musl.

We have already the patch "0001-cmake-uClibc-Fix-missing-libm-for- tests.patch" for yajl which fixes the missing libm for uClibc for the executable 'gen-extra-close', which should be removed by your patch.

I'm not sure if it's worth, but I would prefer to fix the CMake build files of yajl by checking if libm is needed for isnan and it to the list of LIBS and let all executables link against LIBS. Thomas Petazzoni did this for an autotools package [3]. For CMake it would be something like this:

    # check if isnan needs libm
    try_compile(ISNAN_NEEDS_LIBM, ...)
    if (ISNAN_NEEDS_LIBM)
    ? set(LIBS ${LIBS} m)
    endif ()
    [..]

    TARGET_LINK_LIBRARIES(${testProg} yajl ${LIBS})

Furthermore, the .pc file should be fixed.

[1]?http://patchwork.ozlabs.org/patch/612226/ [2]?http://patchwork.ozlabs.org/patch/608412/ [3]?http://lists.busybox.net/pipermail/buildroot/2015-May/127381.html

Best regards
J?rg Krause

#2 lore raw

PATCH 1/1 yajl: fix build with uClibc

Hi Vicente, J?rg,

Quoted 14 lines · J?rg Krause

(...)

I'm not sure if it's worth, but I would prefer to fix the CMake build files of yajl by checking if libm is needed for isnan and it to the list of LIBS and let all executables link against LIBS. Thomas Petazzoni did this for an autotools package [3]. For CMake it would be something like this:

    # check if isnan needs libm
    try_compile(ISNAN_NEEDS_LIBM, ...)
    if (ISNAN_NEEDS_LIBM)
      set(LIBS ${LIBS} m)
    endif ()
Quoted 4 lines
    [..]

    TARGET_LINK_LIBRARIES(${testProg} yajl ${LIBS})

I just encountered this build issue.
I end up with a patch like that, in yasl Top-level CMakeList.txt :

  # uclibc does not provide isnan() & isinf().
  # Symbol are in libm instead.
  INCLUDE(CheckLibraryExists)
  CHECK_LIBRARY_EXISTS(c isnan "" HAVE_LIBC_ISNAN)
  IF (NOT HAVE_LIBC_ISNAN)
    SET(CMAKE_SHARED_LINKER_FLAGS "-lm ${CMAKE_SHARED_LINKER_FLAGS}")
  ENDIF (NOT HAVE_LIBC_ISNAN)

It works with uClibc based toolchain.

But I am not sure about this patch for compatibility with other C library. I have just test on my host (glibc) with a dummy CMakeList.txt, and :

CHECK_LIBRARY_EXISTS(c isnan "" HAVE_LIBC_ISNAN)

Quoted 1 line
Quoted 1 line

-- Looking for isnan in c
-- Looking for isnan in c - found

Anyway, looking at the man page for isnan & isinf, we are supposed to link against libmath... (Link with -lm)

Regards,

Signature · 3 lines
Beno?t Mauduit
Mail : <[email protected]>
XMPP : <[email protected]>