diff --git a/src/makefiles/Makefile.hpux b/src/makefiles/Makefile.hpux
index 4c4071055825abc3221559bc5cc1d44224131bfa..f8be012b9fa53bd21cbeda7942135eb6f9cb5742 100644
--- a/src/makefiles/Makefile.hpux
+++ b/src/makefiles/Makefile.hpux
@@ -53,10 +53,18 @@ endif
 # Rule for building shared libs (currently used only for regression test
 # shlib ... should go away, since this is not really enough knowledge)
 %$(DLSUFFIX): %.o
-ifeq ($(with_gnu_ld), yes)
-	$(CC) $(LDFLAGS) -shared -o $@ $<
+ifeq ($(GCC), yes)
+  ifeq ($(with_gnu_ld), yes)
+	$(CC) $(LDFLAGS) -shared -o $@ $< `$(CC) $(LDFLAGS) -print-libgcc-file-name`
+  else
+	$(LD) -b -o $@ $< `$(CC) $(LDFLAGS) -print-libgcc-file-name`
+  endif
 else
+  ifeq ($(with_gnu_ld), yes)
+	$(CC) $(LDFLAGS) -shared -o $@ $<
+  else
 	$(LD) -b -o $@ $<
+  endif
 endif
 
 sqlmansect = 5