]> granicus.if.org Git - json-c/commitdiff
Link against libm when needed
authorThomas Petazzoni <thomas.petazzoni@free-electrons.com>
Fri, 1 May 2015 10:52:18 +0000 (12:52 +0200)
committerThomas Petazzoni <thomas.petazzoni@free-electrons.com>
Fri, 1 May 2015 11:01:17 +0000 (13:01 +0200)
In certain C libraries (e.g uClibc), isnan() and related functions are
implemented in libm, so json-c needs to link against it. This commit
therefore adds an AC_TRY_LINK() test to check whether a program
calling isnan() can be properly linked with no special flags. If not,
we assume linking against libm is needed.

The json-c.pc.in file is also adjusted so that in the case of static
linking against json-c, -lm is also used.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
configure.ac
json-c.pc.in

index c50f81bde0167429d1f79cd1e09a2e2e0854776e..30e717453432a5e69720cc3df459b1810d41ee2b 100644 (file)
@@ -50,6 +50,10 @@ AC_CHECK_DECLS([isinf], [], [], [[#include <math.h>]])
 AC_CHECK_DECLS([_isnan], [], [], [[#include <float.h>]])
 AC_CHECK_DECLS([_finite], [], [], [[#include <float.h>]])
 
+if test "$ac_cv_have_decl_isnan" = "yes" ; then
+   AC_TRY_LINK([#include <math.h>], [float f = 0.0; return isnan(f)], [], [LIBS="$LIBS -lm"])
+fi
+
 #check if .section.gnu.warning accepts long strings (for __warn_references)
 AC_LANG_PUSH([C])
 
index 037739d27b776fd57d871350b23903f24ffc0b03..05bfbc8cdd5bd4b911e5f4fa36c8639fd86c92b3 100644 (file)
@@ -6,6 +6,7 @@ includedir=@includedir@
 Name: json-c
 Description: JSON implementation in C
 Version: @VERSION@
-Requires: 
+Requires:
+Libs.private: @LIBS@
 Libs:  -L${libdir} -ljson-c
 Cflags: -I${includedir}/json-c