--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -179,7 +179,7 @@
 libraptor2_la_LIBADD += $(top_builddir)/librdfa/librdfa.la
 endif
 
-libraptor2_la_LDFLAGS = -version-info @RAPTOR_LIBTOOL_VERSION@ \
+libraptor2_la_LDFLAGS = -no-undefined -version-info @RAPTOR_LIBTOOL_VERSION@ \
 @RAPTOR_LDFLAGS@ $(MEM_LIBS)
 libraptor2_la_LIBADD += @LTLIBOBJS@
 
--- a/src/sort_r.h
+++ b/src/sort_r.h
@@ -27,7 +27,7 @@
      defined AMIGA)
 #  define _SORT_R_BSD
 #elif (defined _GNU_SOURCE || defined __gnu_hurd__ || defined __GNU__ || \
-       defined __linux__ || defined __MINGW32__ || defined __GLIBC__ || \
+       defined __linux__ || defined __GLIBC__ || \
        defined __CYGWIN__)
 #  define _SORT_R_LINUX
 #elif (defined _WIN32 || defined _WIN64 || defined __WINDOWS__)
@@ -61,6 +61,19 @@
 
 #else /* !NESTED_QSORT */
 
+  #if !defined _SORT_R_LINUX
+  struct sort_r_data
+  {
+    void *arg;
+    int (*compar)(const void *_a, const void *_b, void *_arg);
+  };
+  static inline int sort_r_arg_swap(void *s, const void *a, const void *b)
+  {
+    struct sort_r_data *ss = (struct sort_r_data*)s;
+    return (ss->compar)(a, b, ss->arg);
+  }
+  #endif
+
   /* Declare structs and functions */
   #if defined _SORT_R_BSD
 
@@ -68,18 +81,6 @@
     extern void qsort_r(void *base, size_t nel, size_t width, void *thunk,
                         int (*compar)(void *_thunk, const void *_a, const void *_b));
 
-    struct sort_r_data
-    {
-      void *arg;
-      int (*compar)(const void *_a, const void *_b, void *_arg);
-    };
-
-    static inline int sort_r_arg_swap(void *s, const void *a, const void *b)
-    {
-      struct sort_r_data *ss = (struct sort_r_data*)s;
-      return (ss->compar)(a, b, ss->arg);
-    }
-
   #elif defined _SORT_R_LINUX
 
     typedef int(* __compar_d_fn_t)(const void *, const void *, void *);
