qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] configure: properly check if -lrt and -lm is needed
@ 2012-06-14 14:51 Natanael Copa
  2012-08-16 13:22 ` [Qemu-devel] [PATCH v2] " Natanael Copa
  0 siblings, 1 reply; 18+ messages in thread
From: Natanael Copa @ 2012-06-14 14:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: Natanael Copa

Fixes build against uClibc.

uClibc provides 2 versions of clock_gettime(), one with realtime
support and one without (this is so you can avoid linking in -lrt
unless actually needed). This means that the clock_gettime() don't
need -lrt. We still need it for timer_create() so we check for this
function in addition.

We also need check if -lm is needed for isnan().

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
---
 Makefile        |    4 ++--
 Makefile.target |    4 +---
 configure       |   33 +++++++++++++++++++++++++++++++--
 3 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/Makefile b/Makefile
index 32550cb..9dfa01a 100644
--- a/Makefile
+++ b/Makefile
@@ -35,7 +35,7 @@ configure: ;
 
 $(call set-vpath, $(SRC_PATH))
 
-LIBS+=-lz $(LIBS_TOOLS)
+LIBS+=-lz $(LIBS_TOOLS) $(LIBM) $(LIBRT)
 
 HELPERS-$(CONFIG_LINUX) = qemu-bridge-helper$(EXESUF)
 
@@ -172,7 +172,7 @@ qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx
 	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@,"  GEN   $@")
 
 qapi-dir := $(BUILD_DIR)/qapi-generated
-qemu-ga$(EXESUF): LIBS = $(LIBS_QGA)
+qemu-ga$(EXESUF): LIBS = $(LIBS_QGA) $(LIBRT) $(LIBM)
 qemu-ga$(EXESUF): QEMU_CFLAGS += -I $(qapi-dir)
 
 gen-out-type = $(subst .,-,$(suffix $@))
diff --git a/Makefile.target b/Makefile.target
index 2907aad..d214d2c 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -34,9 +34,7 @@ PROGS+=$(QEMU_PROGW)
 endif
 STPFILES=
 
-ifndef CONFIG_HAIKU
-LIBS+=-lm
-endif
+LIBS+=$(LIBM) $(LIBRT)
 
 config-target.h: config-target.h-timestamp
 config-target.h-timestamp: config-target.mak
diff --git a/configure b/configure
index c2366ee..f925973 100755
--- a/configure
+++ b/configure
@@ -102,6 +102,8 @@ audio_win_int=""
 cc_i386=i386-pc-linux-gnu-gcc
 libs_qga=""
 debug_info="yes"
+libm=""
+librt=""
 
 target_list=""
 
@@ -2568,17 +2570,42 @@ fi
 
 
 ##########################################
+# Do we need libm
+cat > $TMPC << EOF
+#include <math.h>
+int main(void) { return isnan(0.0); }
+EOF
+if compile_prog "" "" ; then
+  libm=
+elif compile_prog "" "-lm" ; then
+  libm="-lm"
+else
+  echo
+  echo "Error: libm check failed"
+  echo
+  exit 1
+fi
+
+##########################################
 # Do we need librt
 cat > $TMPC <<EOF
 #include <signal.h>
 #include <time.h>
-int main(void) { return clock_gettime(CLOCK_REALTIME, NULL); }
+int main(void) {
+  timer_create(CLOCK_REALTIME, NULL, NULL);
+  return clock_gettime(CLOCK_REALTIME, NULL);
+}
 EOF
 
 if compile_prog "" "" ; then
   :
 elif compile_prog "" "-lrt" ; then
-  LIBS="-lrt $LIBS"
+  librt="-lrt"
+else
+  echo
+  echo "Error: librt check failed"
+  echo
+  exit 1
 fi
 
 if test "$darwin" != "yes" -a "$mingw32" != "yes" -a "$solaris" != yes -a \
@@ -3442,6 +3469,8 @@ echo "LIBS_TOOLS+=$libs_tools" >> $config_host_mak
 echo "EXESUF=$EXESUF" >> $config_host_mak
 echo "LIBS_QGA+=$libs_qga" >> $config_host_mak
 echo "POD2MAN=$POD2MAN" >> $config_host_mak
+echo "LIBM=$libm" >> $config_host_mak
+echo "LIBRT=$librt" >> $config_host_mak
 
 # generate list of library paths for linker script
 
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [Qemu-devel] [PATCH v2] configure: properly check if -lrt and -lm is needed
  2012-06-14 14:51 [Qemu-devel] [PATCH] configure: properly check if -lrt and -lm is needed Natanael Copa
@ 2012-08-16 13:22 ` Natanael Copa
  2012-08-20 12:19   ` Juan Quintela
                     ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: Natanael Copa @ 2012-08-16 13:22 UTC (permalink / raw)
  To: qemu-devel; +Cc: Natanael Copa

Fixes build against uClibc.

uClibc provides 2 versions of clock_gettime(), one with realtime
support and one without (this is so you can avoid linking in -lrt
unless actually needed). This means that the clock_gettime() don't
need -lrt. We still need it for timer_create() so we check for this
function in addition.

We also need check if -lm is needed for isnan().

Both -lm and -lrt are needed for libs_qga.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
---
The Xen people have nagged me to get this patch upstream so I have come
up with a rebased v2 patch after consulting with pm215 on IRC.

Please consider include this.

Changes v1->v2:
 - Check for sin() in addition to isnan()
 - Add comment on why we also check for timer_create
 - Use $LIBS and $libs_qga instead of $libm and $librt, based on
   feedback from pm215 on IRC
 - Do not remove the explicit add of -lm unless Haiku. This was due
   to http://www.mail-archive.com/qemu-devel@nongnu.org/msg102965.html
   I am not sure if this is valid, though.

 configure | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index edf9da4..a351f9b 100755
--- a/configure
+++ b/configure
@@ -2624,17 +2624,48 @@ fi
 
 
 ##########################################
+# Do we need libm
+cat > $TMPC << EOF
+#include <math.h>
+int main(void) { return isnan(sin(0.0)); }
+EOF
+if compile_prog "" "" ; then
+  :
+elif compile_prog "" "-lm" ; then
+  LIBS="-lm $LIBS"
+  libs_qga="-lm $libs_qga"
+else
+  echo
+  echo "Error: libm check failed"
+  echo
+  exit 1
+fi
+
+##########################################
 # Do we need librt
+# uClibc provides 2 versions of clock_gettime(), one with realtime
+# support and one without. This means that the clock_gettime() don't
+# need -lrt. We still need it for timer_create() so we check for this
+# function in addition.
 cat > $TMPC <<EOF
 #include <signal.h>
 #include <time.h>
-int main(void) { return clock_gettime(CLOCK_REALTIME, NULL); }
+int main(void) {
+  timer_create(CLOCK_REALTIME, NULL, NULL);
+  return clock_gettime(CLOCK_REALTIME, NULL);
+}
 EOF
 
 if compile_prog "" "" ; then
   :
 elif compile_prog "" "-lrt" ; then
   LIBS="-lrt $LIBS"
+  libs_qga="-lrt $libs_qga"
+else
+  echo
+  echo "Error: librt check failed"
+  echo
+  exit 1
 fi
 
 if test "$darwin" != "yes" -a "$mingw32" != "yes" -a "$solaris" != yes -a \
-- 
1.7.11.4

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [PATCH v2] configure: properly check if -lrt and -lm is needed
  2012-08-16 13:22 ` [Qemu-devel] [PATCH v2] " Natanael Copa
@ 2012-08-20 12:19   ` Juan Quintela
  2012-08-20 12:43   ` Peter Maydell
  2012-08-20 13:27   ` [Qemu-devel] [PATCH v2] " Peter Maydell
  2 siblings, 0 replies; 18+ messages in thread
From: Juan Quintela @ 2012-08-20 12:19 UTC (permalink / raw)
  To: Natanael Copa; +Cc: Natanael Copa, qemu-devel

Natanael Copa <natanael.copa@gmail.com> wrote:
> Fixes build against uClibc.
>
> uClibc provides 2 versions of clock_gettime(), one with realtime
> support and one without (this is so you can avoid linking in -lrt
> unless actually needed). This means that the clock_gettime() don't
> need -lrt. We still need it for timer_create() so we check for this
> function in addition.
>
> We also need check if -lm is needed for isnan().
>
> Both -lm and -lrt are needed for libs_qga.
>
> Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>

Reviewed-by: Juan Quintela <quintela@redhat.com>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [PATCH v2] configure: properly check if -lrt and -lm is needed
  2012-08-16 13:22 ` [Qemu-devel] [PATCH v2] " Natanael Copa
  2012-08-20 12:19   ` Juan Quintela
@ 2012-08-20 12:43   ` Peter Maydell
  2012-08-20 19:53     ` Blue Swirl
  2012-08-20 13:27   ` [Qemu-devel] [PATCH v2] " Peter Maydell
  2 siblings, 1 reply; 18+ messages in thread
From: Peter Maydell @ 2012-08-20 12:43 UTC (permalink / raw)
  To: Natanael Copa; +Cc: Blue Swirl, Natanael Copa, qemu-devel

On 16 August 2012 14:22, Natanael Copa <natanael.copa@gmail.com> wrote:
> Fixes build against uClibc.
>
> uClibc provides 2 versions of clock_gettime(), one with realtime
> support and one without (this is so you can avoid linking in -lrt
> unless actually needed). This means that the clock_gettime() don't
> need -lrt. We still need it for timer_create() so we check for this
> function in addition.
>
> We also need check if -lm is needed for isnan().
>
> Both -lm and -lrt are needed for libs_qga.
>
> Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
> ---
> The Xen people have nagged me to get this patch upstream so I have come
> up with a rebased v2 patch after consulting with pm215 on IRC.
>
> Please consider include this.
>
> Changes v1->v2:
>  - Check for sin() in addition to isnan()
>  - Add comment on why we also check for timer_create
>  - Use $LIBS and $libs_qga instead of $libm and $librt, based on
>    feedback from pm215 on IRC
>  - Do not remove the explicit add of -lm unless Haiku. This was due
>    to http://www.mail-archive.com/qemu-devel@nongnu.org/msg102965.html
>    I am not sure if this is valid, though.

Certainly building a linux-user target works for me even without
that explicit 'LIBS+=-lm' in Makefile.target. Blue, can you remember
what you had in mind when you wrote that email?

thanks
-- PMM

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [PATCH v2] configure: properly check if -lrt and -lm is needed
  2012-08-16 13:22 ` [Qemu-devel] [PATCH v2] " Natanael Copa
  2012-08-20 12:19   ` Juan Quintela
  2012-08-20 12:43   ` Peter Maydell
@ 2012-08-20 13:27   ` Peter Maydell
  2012-08-20 14:33     ` Natanael Copa
  2 siblings, 1 reply; 18+ messages in thread
From: Peter Maydell @ 2012-08-20 13:27 UTC (permalink / raw)
  To: Natanael Copa; +Cc: Blue Swirl, Natanael Copa, qemu-devel

On 16 August 2012 14:22, Natanael Copa <natanael.copa@gmail.com> wrote:
> Fixes build against uClibc.
>
> uClibc provides 2 versions of clock_gettime(), one with realtime
> support and one without (this is so you can avoid linking in -lrt
> unless actually needed). This means that the clock_gettime() don't
> need -lrt. We still need it for timer_create() so we check for this
> function in addition.
>
> We also need check if -lm is needed for isnan().
>
> Both -lm and -lrt are needed for libs_qga.

This patch breaks building the linux-user targets with --static:

cam-vm-266:precise:qemu$ ./configure --target-list=arm-linux-user --static

Error: librt check failed


The test program is failing to link with this
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/librt.a(timer_create.o):
In function `timer_create':
(.text+0x121): undefined reference to `pthread_once'

and a lot of similar errors.

(This seems to me like a glibc bug but since it's out there we rather
have to deal with it I think.)

-- PMM

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [PATCH v2] configure: properly check if -lrt and -lm is needed
  2012-08-20 13:27   ` [Qemu-devel] [PATCH v2] " Peter Maydell
@ 2012-08-20 14:33     ` Natanael Copa
  2012-08-20 14:41       ` Peter Maydell
  0 siblings, 1 reply; 18+ messages in thread
From: Natanael Copa @ 2012-08-20 14:33 UTC (permalink / raw)
  To: Peter Maydell; +Cc: Blue Swirl, Natanael Copa, qemu-devel

On Mon, Aug 20, 2012 at 3:27 PM, Peter Maydell <peter.maydell@linaro.org> wrote:
> On 16 August 2012 14:22, Natanael Copa <natanael.copa@gmail.com> wrote:
>> Fixes build against uClibc.
>>
>> uClibc provides 2 versions of clock_gettime(), one with realtime
>> support and one without (this is so you can avoid linking in -lrt
>> unless actually needed). This means that the clock_gettime() don't
>> need -lrt. We still need it for timer_create() so we check for this
>> function in addition.
>>
>> We also need check if -lm is needed for isnan().
>>
>> Both -lm and -lrt are needed for libs_qga.
>
> This patch breaks building the linux-user targets with --static:
>
> cam-vm-266:precise:qemu$ ./configure --target-list=arm-linux-user --static
>
> Error: librt check failed
>
>
> The test program is failing to link with this
> /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/librt.a(timer_create.o):
> In function `timer_create':
> (.text+0x121): undefined reference to `pthread_once'
>
> and a lot of similar errors.

smells missing -lpthread.

> (This seems to me like a glibc bug but since it's out there we rather
> have to deal with it I think.)

Agree.

Will configure pass if you:
--- a/configure
+++ b/configure
@@ -2661,6 +2661,10 @@ if compile_prog "" "" ; then
 elif compile_prog "" "-lrt" ; then
   LIBS="-lrt $LIBS"
   libs_qga="-lrt $libs_qga"
+# we might need -lpthread in case static linking on glibc
+elif compile_prog "" "-lrt -lpthread" ; then
+  LIBS="-lrt -lpthread $LIBS"
+  libs_qga="-lrt -lpthread $libs_qga"
 else
   echo
   echo "Error: librt check failed"



Thanks for feedback!

-- 
Natanael Copa

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [PATCH v2] configure: properly check if -lrt and -lm is needed
  2012-08-20 14:33     ` Natanael Copa
@ 2012-08-20 14:41       ` Peter Maydell
  2012-08-20 15:05         ` [Qemu-devel] [PATCH v3] " Natanael Copa
  0 siblings, 1 reply; 18+ messages in thread
From: Peter Maydell @ 2012-08-20 14:41 UTC (permalink / raw)
  To: Natanael Copa; +Cc: Blue Swirl, Natanael Copa, qemu-devel

On 20 August 2012 15:33, Natanael Copa <natanael.copa@gmail.com> wrote:
> On Mon, Aug 20, 2012 at 3:27 PM, Peter Maydell <peter.maydell@linaro.org> wrote:
>> The test program is failing to link with this
>> /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/librt.a(timer_create.o):
>> In function `timer_create':
>> (.text+0x121): undefined reference to `pthread_once'
>>
>> and a lot of similar errors.
>
> smells missing -lpthread.
>
>> (This seems to me like a glibc bug but since it's out there we rather
>> have to deal with it I think.)
>
> Agree.
>
> Will configure pass if you:
> --- a/configure
> +++ b/configure
> @@ -2661,6 +2661,10 @@ if compile_prog "" "" ; then
>  elif compile_prog "" "-lrt" ; then
>    LIBS="-lrt $LIBS"
>    libs_qga="-lrt $libs_qga"
> +# we might need -lpthread in case static linking on glibc
> +elif compile_prog "" "-lrt -lpthread" ; then
> +  LIBS="-lrt -lpthread $LIBS"
> +  libs_qga="-lrt -lpthread $libs_qga"
>  else
>    echo
>    echo "Error: librt check failed"

Yes, that will work.

-- PMM

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [Qemu-devel] [PATCH v3] configure: properly check if -lrt and -lm is needed
  2012-08-20 14:41       ` Peter Maydell
@ 2012-08-20 15:05         ` Natanael Copa
  0 siblings, 0 replies; 18+ messages in thread
From: Natanael Copa @ 2012-08-20 15:05 UTC (permalink / raw)
  To: qemu-devel; +Cc: Natanael Copa

Fixes build against uClibc.

uClibc provides 2 versions of clock_gettime(), one with realtime
support and one without (this is so you can avoid linking in -lrt
unless actually needed). This means that the clock_gettime() don't
need -lrt. We still need it for timer_create() so we check for this
function in addition.

We also need check if -lm is needed for isnan().

Both -lm and -lrt are needed for libs_qga.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
---
Changes v2->v3:
- Check if -lpthread is needed with static -lrt


 configure | 37 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index edf9da4..3d7fe69 100755
--- a/configure
+++ b/configure
@@ -2624,17 +2624,52 @@ fi
 
 
 ##########################################
+# Do we need libm
+cat > $TMPC << EOF
+#include <math.h>
+int main(void) { return isnan(sin(0.0)); }
+EOF
+if compile_prog "" "" ; then
+  :
+elif compile_prog "" "-lm" ; then
+  LIBS="-lm $LIBS"
+  libs_qga="-lm $libs_qga"
+else
+  echo
+  echo "Error: libm check failed"
+  echo
+  exit 1
+fi
+
+##########################################
 # Do we need librt
+# uClibc provides 2 versions of clock_gettime(), one with realtime
+# support and one without. This means that the clock_gettime() don't
+# need -lrt. We still need it for timer_create() so we check for this
+# function in addition.
 cat > $TMPC <<EOF
 #include <signal.h>
 #include <time.h>
-int main(void) { return clock_gettime(CLOCK_REALTIME, NULL); }
+int main(void) {
+  timer_create(CLOCK_REALTIME, NULL, NULL);
+  return clock_gettime(CLOCK_REALTIME, NULL);
+}
 EOF
 
 if compile_prog "" "" ; then
   :
 elif compile_prog "" "-lrt" ; then
   LIBS="-lrt $LIBS"
+  libs_qga="-lrt $libs_qga"
+# we might need -lpthread in case static linking
+elif compile_prog "" "-lrt -lpthread" ; then
+  LIBS="-lrt -lpthread $LIBS"
+  libs_qga="-lrt -lpthread $libs_qga"
+else
+  echo
+  echo "Error: librt check failed"
+  echo
+  exit 1
 fi
 
 if test "$darwin" != "yes" -a "$mingw32" != "yes" -a "$solaris" != yes -a \
-- 
1.7.12

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [PATCH v2] configure: properly check if -lrt and -lm is needed
  2012-08-20 12:43   ` Peter Maydell
@ 2012-08-20 19:53     ` Blue Swirl
  2012-08-21  6:10       ` Natanael Copa
  0 siblings, 1 reply; 18+ messages in thread
From: Blue Swirl @ 2012-08-20 19:53 UTC (permalink / raw)
  To: Peter Maydell; +Cc: Natanael Copa, qemu-devel, Natanael Copa

On Mon, Aug 20, 2012 at 12:43 PM, Peter Maydell
<peter.maydell@linaro.org> wrote:
> On 16 August 2012 14:22, Natanael Copa <natanael.copa@gmail.com> wrote:
>> Fixes build against uClibc.
>>
>> uClibc provides 2 versions of clock_gettime(), one with realtime
>> support and one without (this is so you can avoid linking in -lrt
>> unless actually needed). This means that the clock_gettime() don't
>> need -lrt. We still need it for timer_create() so we check for this
>> function in addition.
>>
>> We also need check if -lm is needed for isnan().
>>
>> Both -lm and -lrt are needed for libs_qga.
>>
>> Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
>> ---
>> The Xen people have nagged me to get this patch upstream so I have come
>> up with a rebased v2 patch after consulting with pm215 on IRC.
>>
>> Please consider include this.
>>
>> Changes v1->v2:
>>  - Check for sin() in addition to isnan()
>>  - Add comment on why we also check for timer_create
>>  - Use $LIBS and $libs_qga instead of $libm and $librt, based on
>>    feedback from pm215 on IRC
>>  - Do not remove the explicit add of -lm unless Haiku. This was due
>>    to http://www.mail-archive.com/qemu-devel@nongnu.org/msg102965.html
>>    I am not sure if this is valid, though.
>
> Certainly building a linux-user target works for me even without
> that explicit 'LIBS+=-lm' in Makefile.target. Blue, can you remember
> what you had in mind when you wrote that email?

Build failed since math library functions (sin() etc.) were not found.

>
> thanks
> -- PMM

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [PATCH v2] configure: properly check if -lrt and -lm is needed
  2012-08-20 19:53     ` Blue Swirl
@ 2012-08-21  6:10       ` Natanael Copa
  2012-08-21 18:12         ` Blue Swirl
  0 siblings, 1 reply; 18+ messages in thread
From: Natanael Copa @ 2012-08-21  6:10 UTC (permalink / raw)
  To: Blue Swirl; +Cc: Peter Maydell, qemu-devel, Natanael Copa

On Mon, 20 Aug 2012 19:53:22 +0000
Blue Swirl <blauwirbel@gmail.com> wrote:

> >>  - Do not remove the explicit add of -lm unless Haiku. This was due
> >>    to
> >> http://www.mail-archive.com/qemu-devel@nongnu.org/msg102965.html I
> >> am not sure if this is valid, though.
> >
> > Certainly building a linux-user target works for me even without
> > that explicit 'LIBS+=-lm' in Makefile.target. Blue, can you remember
> > what you had in mind when you wrote that email?
> 
> Build failed since math library functions (sin() etc.) were not found.

The v2 and v3 patches I sent tests for sin() in addition to isnan (which
normally is a macro). It might explain why it works now.

Adding a second -lm does not hurt, but omitting it when needed breaks
build on uclibc for sure, so it would be nice if the v3 patch could be
applied.

Thanks!

-nc

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [PATCH v2] configure: properly check if -lrt and -lm is needed
  2012-08-21  6:10       ` Natanael Copa
@ 2012-08-21 18:12         ` Blue Swirl
  2012-08-22 11:23           ` [Qemu-devel] [PATCH v4] " Natanael Copa
  0 siblings, 1 reply; 18+ messages in thread
From: Blue Swirl @ 2012-08-21 18:12 UTC (permalink / raw)
  To: Natanael Copa; +Cc: Peter Maydell, qemu-devel

On Tue, Aug 21, 2012 at 6:10 AM, Natanael Copa <ncopa@alpinelinux.org> wrote:
> On Mon, 20 Aug 2012 19:53:22 +0000
> Blue Swirl <blauwirbel@gmail.com> wrote:
>
>> >>  - Do not remove the explicit add of -lm unless Haiku. This was due
>> >>    to
>> >> http://www.mail-archive.com/qemu-devel@nongnu.org/msg102965.html I
>> >> am not sure if this is valid, though.
>> >
>> > Certainly building a linux-user target works for me even without
>> > that explicit 'LIBS+=-lm' in Makefile.target. Blue, can you remember
>> > what you had in mind when you wrote that email?
>>
>> Build failed since math library functions (sin() etc.) were not found.
>
> The v2 and v3 patches I sent tests for sin() in addition to isnan (which
> normally is a macro). It might explain why it works now.
>
> Adding a second -lm does not hurt, but omitting it when needed breaks
> build on uclibc for sure, so it would be nice if the v3 patch could be
> applied.

Now I get this on mingw32:
config-host.mak is out-of-date, running configure

Error: librt check failed

>
> Thanks!
>
> -nc

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [Qemu-devel] [PATCH v4] configure: properly check if -lrt and -lm is needed
  2012-08-21 18:12         ` Blue Swirl
@ 2012-08-22 11:23           ` Natanael Copa
  2012-08-28  7:33             ` Natanael Copa
  0 siblings, 1 reply; 18+ messages in thread
From: Natanael Copa @ 2012-08-22 11:23 UTC (permalink / raw)
  To: qemu-devel; +Cc: Natanael Copa

Fixes build against uClibc.

uClibc provides 2 versions of clock_gettime(), one with realtime
support and one without (this is so you can avoid linking in -lrt
unless actually needed). This means that the clock_gettime() don't
need -lrt. We still need it for timer_create() so we check for this
function in addition.

We also need check if -lm is needed for isnan().

Both -lm and -lrt are needed for libs_qga.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
---
Changes v3->v4:
 - Use $pthread_lib from previous pthread test
   We don't need to add it to $LIBS since it should be there already

 configure | 36 ++++++++++++++++++++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index edf9da4..31eee91 100755
--- a/configure
+++ b/configure
@@ -2624,17 +2624,49 @@ fi
 
 
 ##########################################
+# Do we need libm
+cat > $TMPC << EOF
+#include <math.h>
+int main(void) { return isnan(sin(0.0)); }
+EOF
+if compile_prog "" "" ; then
+  :
+elif compile_prog "" "-lm" ; then
+  LIBS="-lm $LIBS"
+  libs_qga="-lm $libs_qga"
+else
+  echo
+  echo "Error: libm check failed"
+  echo
+  exit 1
+fi
+
+##########################################
 # Do we need librt
+# uClibc provides 2 versions of clock_gettime(), one with realtime
+# support and one without. This means that the clock_gettime() don't
+# need -lrt. We still need it for timer_create() so we check for this
+# function in addition.
 cat > $TMPC <<EOF
 #include <signal.h>
 #include <time.h>
-int main(void) { return clock_gettime(CLOCK_REALTIME, NULL); }
+int main(void) {
+  timer_create(CLOCK_REALTIME, NULL, NULL);
+  return clock_gettime(CLOCK_REALTIME, NULL);
+}
 EOF
 
 if compile_prog "" "" ; then
   :
-elif compile_prog "" "-lrt" ; then
+# we need pthread for static linking. use previous pthread test result 
+elif compile_prog "" "-lrt $pthread_lib" ; then
   LIBS="-lrt $LIBS"
+  libs_qga="-lrt $libs_qga"
+else
+  echo
+  echo "Error: librt check failed"
+  echo
+  exit 1
 fi
 
 if test "$darwin" != "yes" -a "$mingw32" != "yes" -a "$solaris" != yes -a \
-- 
1.7.12

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [PATCH v4] configure: properly check if -lrt and -lm is needed
  2012-08-22 11:23           ` [Qemu-devel] [PATCH v4] " Natanael Copa
@ 2012-08-28  7:33             ` Natanael Copa
  2012-08-28 17:16               ` Blue Swirl
  0 siblings, 1 reply; 18+ messages in thread
From: Natanael Copa @ 2012-08-28  7:33 UTC (permalink / raw)
  To: Blue Swirl; +Cc: qemu-devel

On Tue, 21 Aug 2012 18:12:05 +0000
Blue Swirl <blauwirbel@gmail.com> wrote:
> 
> Now I get this on mingw32:
> config-host.mak is out-of-date, running configure
> 
> Error: librt check failed

Any news on the v4 patch, which should fix this?

Thanks!

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [PATCH v4] configure: properly check if -lrt and -lm is needed
  2012-08-28  7:33             ` Natanael Copa
@ 2012-08-28 17:16               ` Blue Swirl
  2012-08-29  6:41                 ` Natanael Copa
  0 siblings, 1 reply; 18+ messages in thread
From: Blue Swirl @ 2012-08-28 17:16 UTC (permalink / raw)
  To: Natanael Copa; +Cc: qemu-devel

On Tue, Aug 28, 2012 at 7:33 AM, Natanael Copa <ncopa@alpinelinux.org> wrote:
> On Tue, 21 Aug 2012 18:12:05 +0000
> Blue Swirl <blauwirbel@gmail.com> wrote:
>>
>> Now I get this on mingw32:
>> config-host.mak is out-of-date, running configure
>>
>> Error: librt check failed
>
> Any news on the v4 patch, which should fix this?

No change:
config-host.mak is out-of-date, running configure

Error: librt check failed

>
> Thanks!
>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [PATCH v4] configure: properly check if -lrt and -lm is needed
  2012-08-28 17:16               ` Blue Swirl
@ 2012-08-29  6:41                 ` Natanael Copa
  2012-09-01  9:13                   ` Blue Swirl
  0 siblings, 1 reply; 18+ messages in thread
From: Natanael Copa @ 2012-08-29  6:41 UTC (permalink / raw)
  To: Blue Swirl; +Cc: qemu-devel

On Tue, 28 Aug 2012 17:16:18 +0000
Blue Swirl <blauwirbel@gmail.com> wrote:

> On Tue, Aug 28, 2012 at 7:33 AM, Natanael Copa
> <ncopa@alpinelinux.org> wrote:
> > On Tue, 21 Aug 2012 18:12:05 +0000
> > Blue Swirl <blauwirbel@gmail.com> wrote:
> >>
> >> Now I get this on mingw32:
> >> config-host.mak is out-of-date, running configure
> >>
> >> Error: librt check failed
> >
> > Any news on the v4 patch, which should fix this?
> 
> No change:
> config-host.mak is out-of-date, running configure
> 
> Error: librt check failed

I have run out of guesses. Could I please have the last lines from your
config.log?

Thanks!

-nc

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [PATCH v4] configure: properly check if -lrt and -lm is needed
  2012-08-29  6:41                 ` Natanael Copa
@ 2012-09-01  9:13                   ` Blue Swirl
  2012-09-12  9:06                     ` [Qemu-devel] [PATCH v5] " Natanael Copa
  0 siblings, 1 reply; 18+ messages in thread
From: Blue Swirl @ 2012-09-01  9:13 UTC (permalink / raw)
  To: Natanael Copa; +Cc: qemu-devel

On Wed, Aug 29, 2012 at 6:41 AM, Natanael Copa <ncopa@alpinelinux.org> wrote:
> On Tue, 28 Aug 2012 17:16:18 +0000
> Blue Swirl <blauwirbel@gmail.com> wrote:
>
>> On Tue, Aug 28, 2012 at 7:33 AM, Natanael Copa
>> <ncopa@alpinelinux.org> wrote:
>> > On Tue, 21 Aug 2012 18:12:05 +0000
>> > Blue Swirl <blauwirbel@gmail.com> wrote:
>> >>
>> >> Now I get this on mingw32:
>> >> config-host.mak is out-of-date, running configure
>> >>
>> >> Error: librt check failed
>> >
>> > Any news on the v4 patch, which should fix this?
>>
>> No change:
>> config-host.mak is out-of-date, running configure
>>
>> Error: librt check failed
>
> I have run out of guesses. Could I please have the last lines from your
> config.log?

i586-mingw32msvc-gcc -m32 -D__USE_MINGW_ANSI_STDIO=1
-DWIN32_LEAN_AND_MEAN -DWINVER=0x501 -D_GNU_SOURCE
-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes
-Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes
-fno-strict-aliasing -fstack-protector-all -Wendif-labels
-Wmissing-include-dirs -Wempty-body -Wnested-externs -Wformat-security
-Wformat-y2k -Winit-self -Wignored-qualifiers -Wold-style-declaration
-Wold-style-definition -Wtype-limits -o
/tmp/qemu-conf-7196-16398-8534.exe /tmp/qemu-conf-21413-16398-5412.c
-m32 -g
/tmp/qemu-conf-21413-16398-5412.c: In function 'main':
/tmp/qemu-conf-21413-16398-5412.c:4: warning: implicit declaration of
function 'timer_create'
/tmp/qemu-conf-21413-16398-5412.c:4: warning: nested extern
declaration of 'timer_create'
/tmp/qemu-conf-21413-16398-5412.c:4: error: 'CLOCK_REALTIME'
undeclared (first use in this function)
/tmp/qemu-conf-21413-16398-5412.c:4: error: (Each undeclared
identifier is reported only once
/tmp/qemu-conf-21413-16398-5412.c:4: error: for each function it appears in.)
/tmp/qemu-conf-21413-16398-5412.c:5: warning: implicit declaration of
function 'clock_gettime'
/tmp/qemu-conf-21413-16398-5412.c:5: warning: nested extern
declaration of 'clock_gettime'
i586-mingw32msvc-gcc -m32 -D__USE_MINGW_ANSI_STDIO=1
-DWIN32_LEAN_AND_MEAN -DWINVER=0x501 -D_GNU_SOURCE
-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes
-Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes
-fno-strict-aliasing -fstack-protector-all -Wendif-labels
-Wmissing-include-dirs -Wempty-body -Wnested-externs -Wformat-security
-Wformat-y2k -Winit-self -Wignored-qualifiers -Wold-style-declaration
-Wold-style-definition -Wtype-limits -o
/tmp/qemu-conf-7196-16398-8534.exe /tmp/qemu-conf-21413-16398-5412.c
-m32 -g -lrt -lpthreadGC2
/tmp/qemu-conf-21413-16398-5412.c: In function 'main':
/tmp/qemu-conf-21413-16398-5412.c:4: warning: implicit declaration of
function 'timer_create'
/tmp/qemu-conf-21413-16398-5412.c:4: warning: nested extern
declaration of 'timer_create'
/tmp/qemu-conf-21413-16398-5412.c:4: error: 'CLOCK_REALTIME'
undeclared (first use in this function)
/tmp/qemu-conf-21413-16398-5412.c:4: error: (Each undeclared
identifier is reported only once
/tmp/qemu-conf-21413-16398-5412.c:4: error: for each function it appears in.)
/tmp/qemu-conf-21413-16398-5412.c:5: warning: implicit declaration of
function 'clock_gettime'
/tmp/qemu-conf-21413-16398-5412.c:5: warning: nested extern
declaration of 'clock_gettime'

>
> Thanks!
>
> -nc

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [Qemu-devel] [PATCH v5] configure: properly check if -lrt and -lm is needed
  2012-09-01  9:13                   ` Blue Swirl
@ 2012-09-12  9:06                     ` Natanael Copa
  2012-09-15 17:26                       ` Blue Swirl
  0 siblings, 1 reply; 18+ messages in thread
From: Natanael Copa @ 2012-09-12  9:06 UTC (permalink / raw)
  To: qemu-devel; +Cc: Blue Swirl, Natanael Copa

Fixes build against uClibc.

uClibc provides 2 versions of clock_gettime(), one with realtime
support and one without (this is so you can avoid linking in -lrt
unless actually needed). This means that the clock_gettime() don't
need -lrt. We still need it for timer_create() so we check for this
function in addition.

We also need check if -lm is needed for isnan().

Both -lm and -lrt are needed for libs_qga.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
---
Changes v4->v5:

 - Do not exit with error if librt fails.
   Apparently, mingw32 does not use those functions at all so we
   should not exit with error.

   This is how it originally worked.

 configure | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index edf9da4..c1ed856 100755
--- a/configure
+++ b/configure
@@ -2624,17 +2624,44 @@ fi
 
 
 ##########################################
+# Do we need libm
+cat > $TMPC << EOF
+#include <math.h>
+int main(void) { return isnan(sin(0.0)); }
+EOF
+if compile_prog "" "" ; then
+  :
+elif compile_prog "" "-lm" ; then
+  LIBS="-lm $LIBS"
+  libs_qga="-lm $libs_qga"
+else
+  echo
+  echo "Error: libm check failed"
+  echo
+  exit 1
+fi
+
+##########################################
 # Do we need librt
+# uClibc provides 2 versions of clock_gettime(), one with realtime
+# support and one without. This means that the clock_gettime() don't
+# need -lrt. We still need it for timer_create() so we check for this
+# function in addition.
 cat > $TMPC <<EOF
 #include <signal.h>
 #include <time.h>
-int main(void) { return clock_gettime(CLOCK_REALTIME, NULL); }
+int main(void) {
+  timer_create(CLOCK_REALTIME, NULL, NULL);
+  return clock_gettime(CLOCK_REALTIME, NULL);
+}
 EOF
 
 if compile_prog "" "" ; then
   :
-elif compile_prog "" "-lrt" ; then
+# we need pthread for static linking. use previous pthread test result 
+elif compile_prog "" "-lrt $pthread_lib" ; then
   LIBS="-lrt $LIBS"
+  libs_qga="-lrt $libs_qga"
 fi
 
 if test "$darwin" != "yes" -a "$mingw32" != "yes" -a "$solaris" != yes -a \
-- 
1.7.12

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [PATCH v5] configure: properly check if -lrt and -lm is needed
  2012-09-12  9:06                     ` [Qemu-devel] [PATCH v5] " Natanael Copa
@ 2012-09-15 17:26                       ` Blue Swirl
  0 siblings, 0 replies; 18+ messages in thread
From: Blue Swirl @ 2012-09-15 17:26 UTC (permalink / raw)
  To: Natanael Copa; +Cc: Natanael Copa, qemu-devel

Thanks, applied.

On Wed, Sep 12, 2012 at 9:06 AM, Natanael Copa <natanael.copa@gmail.com> wrote:
> Fixes build against uClibc.
>
> uClibc provides 2 versions of clock_gettime(), one with realtime
> support and one without (this is so you can avoid linking in -lrt
> unless actually needed). This means that the clock_gettime() don't
> need -lrt. We still need it for timer_create() so we check for this
> function in addition.
>
> We also need check if -lm is needed for isnan().
>
> Both -lm and -lrt are needed for libs_qga.
>
> Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
> ---
> Changes v4->v5:
>
>  - Do not exit with error if librt fails.
>    Apparently, mingw32 does not use those functions at all so we
>    should not exit with error.
>
>    This is how it originally worked.
>
>  configure | 31 +++++++++++++++++++++++++++++--
>  1 file changed, 29 insertions(+), 2 deletions(-)
>
> diff --git a/configure b/configure
> index edf9da4..c1ed856 100755
> --- a/configure
> +++ b/configure
> @@ -2624,17 +2624,44 @@ fi
>
>
>  ##########################################
> +# Do we need libm
> +cat > $TMPC << EOF
> +#include <math.h>
> +int main(void) { return isnan(sin(0.0)); }
> +EOF
> +if compile_prog "" "" ; then
> +  :
> +elif compile_prog "" "-lm" ; then
> +  LIBS="-lm $LIBS"
> +  libs_qga="-lm $libs_qga"
> +else
> +  echo
> +  echo "Error: libm check failed"
> +  echo
> +  exit 1
> +fi
> +
> +##########################################
>  # Do we need librt
> +# uClibc provides 2 versions of clock_gettime(), one with realtime
> +# support and one without. This means that the clock_gettime() don't
> +# need -lrt. We still need it for timer_create() so we check for this
> +# function in addition.
>  cat > $TMPC <<EOF
>  #include <signal.h>
>  #include <time.h>
> -int main(void) { return clock_gettime(CLOCK_REALTIME, NULL); }
> +int main(void) {
> +  timer_create(CLOCK_REALTIME, NULL, NULL);
> +  return clock_gettime(CLOCK_REALTIME, NULL);
> +}
>  EOF
>
>  if compile_prog "" "" ; then
>    :
> -elif compile_prog "" "-lrt" ; then
> +# we need pthread for static linking. use previous pthread test result
> +elif compile_prog "" "-lrt $pthread_lib" ; then
>    LIBS="-lrt $LIBS"
> +  libs_qga="-lrt $libs_qga"
>  fi
>
>  if test "$darwin" != "yes" -a "$mingw32" != "yes" -a "$solaris" != yes -a \
> --
> 1.7.12
>

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2012-09-15 17:26 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-14 14:51 [Qemu-devel] [PATCH] configure: properly check if -lrt and -lm is needed Natanael Copa
2012-08-16 13:22 ` [Qemu-devel] [PATCH v2] " Natanael Copa
2012-08-20 12:19   ` Juan Quintela
2012-08-20 12:43   ` Peter Maydell
2012-08-20 19:53     ` Blue Swirl
2012-08-21  6:10       ` Natanael Copa
2012-08-21 18:12         ` Blue Swirl
2012-08-22 11:23           ` [Qemu-devel] [PATCH v4] " Natanael Copa
2012-08-28  7:33             ` Natanael Copa
2012-08-28 17:16               ` Blue Swirl
2012-08-29  6:41                 ` Natanael Copa
2012-09-01  9:13                   ` Blue Swirl
2012-09-12  9:06                     ` [Qemu-devel] [PATCH v5] " Natanael Copa
2012-09-15 17:26                       ` Blue Swirl
2012-08-20 13:27   ` [Qemu-devel] [PATCH v2] " Peter Maydell
2012-08-20 14:33     ` Natanael Copa
2012-08-20 14:41       ` Peter Maydell
2012-08-20 15:05         ` [Qemu-devel] [PATCH v3] " Natanael Copa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).