diff --git a/src/gvmd.c b/src/gvmd.c
index 49b8349..c55c256 100644
--- a/src/gvmd.c
+++ b/src/gvmd.c
@@ -90,7 +90,10 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <unistd.h>
-#include <execinfo.h>
+
+#ifdef HAVE_EXECINFO_H
+#include <execinfo.h> /* for backtrace() */
+#endif

 #include <gvm/base/pidfile.h>
 #include <gvm/base/pwpolicy.h>
@@ -949,6 +952,7 @@ handle_sigabrt (int given_signal)
   if (in_sigabrt) _exit (EXIT_FAILURE);
   in_sigabrt = 1;

+#ifdef HAVE_EXECINFO_H
   void *frames[BA_SIZE];
   int frame_count, index;
   char **frames_text;
@@ -964,6 +968,7 @@ handle_sigabrt (int given_signal)
   for (index = 0; index < frame_count; index++)
     g_debug ("BACKTRACE: %s", frames_text[index]);
   free (frames_text);
+#endif

   manage_cleanup_process_error (given_signal);
   cleanup ();
@@ -990,9 +995,12 @@ handle_termination_signal (int signal)
  *
  * @param[in]  given_signal  The signal that caused this function to run.
  */
+
 static void
 handle_sigsegv (/* unused */ int given_signal)
 {
+
+#ifdef HAVE_EXECINFO_H
   void *frames[BA_SIZE];
   int frame_count, index;
   char **frames_text;
@@ -1008,6 +1016,7 @@ handle_sigsegv (/* unused */ int given_signal)
   for (index = 0; index < frame_count; index++)
     g_debug ("BACKTRACE: %s", frames_text[index]);
   free (frames_text);
+#endif

   manage_cleanup_process_error (given_signal);

diff --git a/src/sql_pg.c b/src/sql_pg.c
index 8b1a9dd..918f458 100644
--- a/src/sql_pg.c
+++ b/src/sql_pg.c
@@ -178,7 +178,7 @@ sql_is_open ()
   return conn ? 1 : 0;
 }

-#ifndef NDEBUG
+#ifdef HAVE_EXECINFO_H
 #include <execinfo.h>

 /**
@@ -222,7 +222,7 @@ log_notice (void *arg, const PGresult *result)
   g_debug ("PQ notice: context:\n%s",
            PQresultErrorField (result, PG_DIAG_CONTEXT));

-#ifndef NDEBUG
+#ifdef HAVE_EXECINFO_H
   void *frames[BA_SIZE];
   int frame_count, index;
   char **frames_text;
