diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py
index 2e23858827130507f19fd8bc0bfceacfa0d8badc..6eb9e9612245fe3e09ecaf76b01c7768a0861c9e 100644
--- a/Cython/Compiler/ModuleNode.py
+++ b/Cython/Compiler/ModuleNode.py
@@ -2338,6 +2338,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
             wmain = "wmain"
         else:
             wmain = Options.embed
+        main_method = UtilityCode.load_cached("MainFunction", "Embed.c")
         code.globalstate.use_utility_code(
             main_method.specialize(
                 module_name=env.module_name,
@@ -2942,8 +2943,6 @@ bad:
 
 refnanny_utility_code = UtilityCode.load("Refnanny", "ModuleSetupCode.c")
 
-main_method = UtilityCode.load("MainFunction", "Embed.c")
-
 packed_struct_utility_code = UtilityCode(proto="""
 #if defined(__GNUC__)
 #define __Pyx_PACKED __attribute__((__packed__))