diff --git a/src/gdbus-codegen.c b/src/gdbus-codegen.c
index 340d0c9..3b18b96 100644
--- a/src/gdbus-codegen.c
+++ b/src/gdbus-codegen.c
@@ -673,6 +673,7 @@ extended_method_info_get (App *app,
   ExtendedMethodInfo *ei;
   guint n;
   GString *str;
+  gchar *safe_prefix;
 
   /* TODO: cache this data and free all at end */
 
@@ -748,7 +749,9 @@ extended_method_info_get (App *app,
       if (str->str[n] == ',')
         str->str[n] = '_';
     }
-  ei->marshaller_name = g_strdup_printf ("_%s_gdbus_cclosure_marshaller_BOOLEAN__%s", app->output_prefix, str->str + 8);
+  safe_prefix = _hyphen_to_uscore (app->output_prefix);
+  ei->marshaller_name = g_strdup_printf ("_%s_gdbus_cclosure_marshaller_BOOLEAN__%s", safe_prefix, str->str + 8);
+  g_free (safe_prefix);
   g_string_free (str, TRUE);
 
   return ei;
@@ -764,6 +767,7 @@ extended_signal_info_get (App *app,
   ExtendedSignalInfo *ei;
   guint n;
   GString *str;
+  gchar *safe_prefix;
 
   /* TODO: cache this data and free all at end */
 
@@ -839,7 +843,9 @@ extended_signal_info_get (App *app,
           if (str->str[n] == ',')
             str->str[n] = '_';
         }
-      ei->marshaller_name = g_strdup_printf ("_%s_gdbus_cclosure_marshaller_VOID__%s", app->output_prefix, str->str + 5);
+      safe_prefix = _hyphen_to_uscore (app->output_prefix);
+      ei->marshaller_name = g_strdup_printf ("_%s_gdbus_cclosure_marshaller_VOID__%s", safe_prefix, str->str + 5);
+      g_free (safe_prefix);
       g_string_free (str, TRUE);
     }
   else
@@ -5224,12 +5230,15 @@ app_generate_marshallers (App      *app,
     {
       gchar *standard_output;
       gchar *command_line;
+      gchar *safe_prefix;
       int exit_status;
 
+      safe_prefix = _hyphen_to_uscore (app->output_prefix);
       command_line = g_strdup_printf ("glib-genmarshal %s --prefix=_%s_gdbus_cclosure_marshaller %s",
                                       n == 0 ? "--header" : "--body",
-                                      app->output_prefix,
+                                      safe_prefix,
                                       list_filename);
+      g_free (safe_prefix);
       if (!g_spawn_command_line_sync (command_line,
                                       &standard_output,
                                       NULL,
@@ -5444,7 +5453,7 @@ main (gint argc, gchar *argv[])
   app->namespace = opt_namespace != NULL ? opt_namespace : g_strdup ("");
   app->strip_prefix = opt_strip_prefix;
   app->output_prefix = opt_output_prefix != NULL ? opt_output_prefix : g_strdup ("generated");
-  app->output_prefix_upper = g_strdup (app->output_prefix);
+  app->output_prefix_upper = _hyphen_to_uscore (app->output_prefix);
   for (n = 0; app->output_prefix_upper[n] != '\0'; n++)
     app->output_prefix_upper[n] = g_ascii_toupper (app->output_prefix_upper[n]);
 
