--- a/portmidi/pm_linux/pmlinux.c
+++ b/portmidi/pm_linux/pmlinux.c
@@ -12,6 +12,9 @@
 
 #include "stdlib.h"
 #include "portmidi.h"
+#include "pmutil.h"
+#include "pminternal.h"
+
 #ifdef PMALSA
   #include "pmlinuxalsa.h"
 #endif
@@ -20,7 +23,10 @@
   #include "pmlinuxnull.h"
 #endif
 
-PmError pm_init()
+PmDeviceID pm_default_input_device_id = -1;
+PmDeviceID pm_default_output_device_id = -1;
+
+void pm_init()
 {
     /* Note: it is not an error for PMALSA to fail to initialize. 
      * It may be a design error that the client cannot query what subsystems
@@ -33,7 +39,15 @@
     #ifdef PMNULL
         pm_linuxnull_init();
     #endif
-    return pmNoError;
+    // this is set when we return to Pm_Initialize, but we need it
+    // now in order to (successfully) call Pm_CountDevices()
+    pm_initialized = TRUE;      
+    pm_default_input_device_id = find_default_device(
+        "/PortMidi/PM_RECOMMENDED_INPUT_DEVICE", TRUE,
+        pm_default_input_device_id);
+    pm_default_output_device_id = find_default_device(
+        "/PortMidi/PM_RECOMMENDED_OUTPUT_DEVICE", FALSE,
+        pm_default_output_device_id);
 }
 
 void pm_term(void)
@@ -43,14 +57,13 @@
     #endif
 }
 
-PmDeviceID pm_default_input_device_id = -1;
-PmDeviceID pm_default_output_device_id = -1;
-
 PmDeviceID Pm_GetDefaultInputDeviceID() { 
+    Pm_Initialize();
     return pm_default_input_device_id; 
 }
 
 PmDeviceID Pm_GetDefaultOutputDeviceID() { 
+    Pm_Initialize();
     return pm_default_output_device_id; 
 }