diff --git a/meson.build b/meson.build
index 72640a178037a1623d52e0a6fed98e4fb5320525..fce95952b9a87114e1fa9b4d57d454c05d261f69 100644
--- a/meson.build
+++ b/meson.build
@@ -58,6 +58,10 @@ find_program('meson',
 find_program('ninja',
              version: '>=1.8.2')
 
+############################################################
+# require objcopy
+find_program('objcopy')
+
 ############################################################
 # compiler object
 #
@@ -321,6 +325,7 @@ elif os == 'darwin'
     cflags += [
         '-DDARWIN',
         '-DPOSIX',
+        '-D_XOPEN_SOURCE',
     ]
     unix = true
     posix = true
@@ -630,7 +635,11 @@ run_command('meson/make_version_macros.pl')
 #
 # list and build them
 message('Checking and building data objects')
-data_objects = run_command('meson/data_object_list_and_build.sh').stdout().strip().split(' ')
+data_objects_compilation = run_command('meson/data_object_list_and_build.sh')
+if data_objects_compilation.returncode() != 0
+    error('There was a problem building the data objects. Please check that you have objcopy installed, and try running meson/data_object_list_and_build.sh from the binary_c root directory manually to check for errors')
+endif
+data_objects = data_objects_compilation.stdout().strip().split(' ')
 
 if get_option('clean_data_objects') == true
     run_command('meson/clean_data_objects.sh')
diff --git a/src/binary_c_code_options.h b/src/binary_c_code_options.h
index 80a7fd53b812455374e598558f16abe37059d240..98a66eb3dbef26df72c1743cd56a213906f581d1 100644
--- a/src/binary_c_code_options.h
+++ b/src/binary_c_code_options.h
@@ -157,7 +157,7 @@
  * provide it through a macro so it's easily changed on other
  * systems.
  */
-#if defined __GNUC__
+#if defined __GNUC__ && defined __HAVE_MALLOC_H__
 #define HAVE_MALLOC_USABLE_SIZE
 #define Malloc_usable_size(X) malloc_usable_size(X)
 #else
diff --git a/src/debug/backtrace-symbols.c b/src/debug/backtrace-symbols.c
index 6d91eb40453f7f583457317758e8b2911adf9bb7..c4627dbe19442b297e0218ccfa82e2029e262411 100644
--- a/src/debug/backtrace-symbols.c
+++ b/src/debug/backtrace-symbols.c
@@ -47,7 +47,9 @@
 #endif // __HAVE_LIBIBERTY_LIBIBERTYH__
 #endif // __HAVE_LIBIBERTY__
 #include <string.h>
+#ifdef __HAVE_MALLOC_H__
 #include <malloc.h>
+#endif//__HAVE_MALLOC_H__
 #include <stdio.h>
 #include <stdlib.h>
 #include <execinfo.h>
diff --git a/src/librinterpolate/rinterpolate.h b/src/librinterpolate/rinterpolate.h
index e23a170603dbba1ea62af6335e03cdb152be807c..aa2e654a42ecef445e43539273785c8f21c360d2 100644
--- a/src/librinterpolate/rinterpolate.h
+++ b/src/librinterpolate/rinterpolate.h
@@ -14,7 +14,6 @@
 #include <math.h>
 #include <float.h>
 #include <stdio.h>
-#include <malloc.h>
 #include "rinterpolate_compiler.h"
 
 /************************************************************
diff --git a/src/librinterpolate/rinterpolate_alloc_hypertable.c b/src/librinterpolate/rinterpolate_alloc_hypertable.c
index c70c767655caec19a1578c27fde57402339403a3..b951aa94e505e8aebbf5d15f25b9bab43f8e0903 100644
--- a/src/librinterpolate/rinterpolate_alloc_hypertable.c
+++ b/src/librinterpolate/rinterpolate_alloc_hypertable.c
@@ -8,9 +8,6 @@
 
 #include "rinterpolate.h"
 #include "rinterpolate_internal.h"
-#ifdef RINTERPOLATE_USE_REALLOC
-#include <malloc.h>
-#endif
 
 void rinterpolate_alloc_hypertable(struct rinterpolate_table_t * RESTRICT const table)
 {
@@ -54,4 +51,4 @@ void rinterpolate_alloc_hypertable(struct rinterpolate_table_t * RESTRICT const
 }
 
 #endif // __HAVE_LIBRINTERPOLATE__
-        
\ No newline at end of file
+