diff --git a/pyopencl/ipython_ext.py b/pyopencl/ipython_ext.py
index 0ceb04f82e3c3b7215901f09519603799628a98d..81fbcdf8669f01415966ec183f2677ed0d5f451b 100644
--- a/pyopencl/ipython_ext.py
+++ b/pyopencl/ipython_ext.py
@@ -71,7 +71,7 @@ class PyOpenCLMagics(Magics):
         header = "%%cl_kernel"
 
         if build_options:
-            header = "%s %s" % (header, build_options)
+            header = '%s -o "%s"' % (header, build_options)
 
         content = "%s\n\n%s" % (header, kernel)