diff --git a/configure.ac b/configure.ac
index 248a2752ca9f39cea8fbb2d535f561d3ba6a5bf4..9a3b2af982a7ef54cd7c9bfe71f990190dbea888 100644
--- a/configure.ac
+++ b/configure.ac
@@ -231,19 +231,20 @@ AS_IF([test "x$with_speex" != xno],
     [AC_MSG_FAILURE(
        [libspeex link test failed.   You may use --without-speex to compile without speex codec support.])]
        )
-    ]
+  ]
 dnl More advanced check in case the libspeexdsp is not installed
-AC_CHECK_LIB(speex, speex_preprocess_run, HAVE_SPEEXDSP=true, HAVE_SPEEXDSP=false)
+AC_SEARCH_LIBS(speex_preprocess_run, speexdsp, HAVE_SPEEXDSP="yes", HAVE_SPEEXDSP="no", [])
 
-if test $HAVE_SPEEXDSP = false; then
- AC_MSG_WARN([The silence detection in speex could not have been enabled])
+if test $HAVE_SPEEXDSP="no"; then
+    echo $HAVE_SPEEXDSP;
+    AC_MSG_WARN([The silence detection in speex could not have been enabled])
 fi
 
 )
 
 AC_DEFINE([HAVE_SPEEX], test "x$with_speex" = "xyes", [Define if you have libspeex])
 AM_CONDITIONAL(BUILD_SPEEX, test "x$with_speex" = "xyes" )
-AM_CONDITIONAL(ENABLE_SPEEXDSP, $HAVE_SPEEXDSP)
+AM_CONDITIONAL(ENABLE_SPEEXDSP, test  $HAVE_SPEEXDSP = yes)
 
 dnl Check for ilbc support
 AC_ARG_WITH([ilbc],
diff --git a/src/audio/codecs/Makefile.am b/src/audio/codecs/Makefile.am
index 6b8097c6ba29b9313607d8bcefd6d7fe9312fa53..8c7d4803848e93c0e4f47ee9f40ebfbe4d0dafc5 100644
--- a/src/audio/codecs/Makefile.am
+++ b/src/audio/codecs/Makefile.am
@@ -10,15 +10,15 @@ INSTALL_GSM_RULE = install-libcodec_gsm_so
 endif
 
 if ENABLE_SPEEXDSP
-SPEEXDSP_LIB = -lspeexdsp
+SPEEXDSP= -DHAVE_SPEEXDSP_LIB
 endif
 
 if BUILD_SPEEX
 SPEEX_LIB = libcodec_speex.so
 libcodec_speex_so_SOURCES = speexcodec.cpp
 libcodec_speex_so_CFLAGS = -fPIC -g -Wall
-libcodec_speex_so_CXXFLAGS = -fPIC -g -Wall
-libcodec_speex_so_LDFLAGS = --shared -lc -lspeex $(SPEEXDSP_LIB) -lm
+libcodec_speex_so_CXXFLAGS = -fPIC -g -Wall $(SPEEXDSP)
+libcodec_speex_so_LDFLAGS = --shared -lc -lspeex $(SPEEX_NIMP)
 INSTALL_SPEEX_RULE = install-libcodec_speex_so
 endif
 
diff --git a/src/audio/codecs/speexcodec.cpp b/src/audio/codecs/speexcodec.cpp
index f325015b1fe46794132bc65edeb3b4713be3c9b1..a2442cbfe869a26af242f4f6b67cbf7ec0326c3b 100644
--- a/src/audio/codecs/speexcodec.cpp
+++ b/src/audio/codecs/speexcodec.cpp
@@ -59,7 +59,7 @@ class Speex : public AudioCodec{
             speex_bits_init(&_speex_enc_bits);
             _speex_enc_state = speex_encoder_init(_speexModePtr);
 
-#if ENABLE_SPEEXDSP
+#ifdef HAVE_SPEEXDSP_LIB
 
             int enable = 1;
             int quality = 10;
@@ -114,10 +114,10 @@ class Speex : public AudioCodec{
         {
             speex_bits_reset(&_speex_enc_bits);
 
-#if ENABLE_SPEEXDSP
+#ifdef HAVE_SPEEXDSP_LIB
             speex_encoder_ctl(_speex_enc_state,SPEEX_SET_SAMPLING_RATE,&_clockRate);
             speex_preprocess_run(_preprocess_state, src);
-#endif
+#endif 
 
             speex_encode_int(_speex_enc_state, src, &_speex_enc_bits);
             int nbBytes = speex_bits_write(&_speex_enc_bits, (char*)dst, size);