From 28abfb4cefc4dae727a0205704af6293c3a605fd Mon Sep 17 00:00:00 2001
From: Justin <62445349+zenarcher007@users.noreply.github.com>
Date: Fri, 17 Jun 2022 10:17:28 -0500
Subject: [PATCH 1/4] Update README.md
---
README.md | 1 -
1 file changed, 1 deletion(-)
diff --git a/README.md b/README.md
index 6fdb6c6..afe3ca1 100644
--- a/README.md
+++ b/README.md
@@ -91,7 +91,6 @@ TODO:
--------
- test on windows
- test on python 2
-- add compiler flags
- add timeit params
From 64946d6b221aed6b77b22f6b9f817d703ba3bba7 Mon Sep 17 00:00:00 2001
From: Justin <62445349+zenarcher007@users.noreply.github.com>
Date: Fri, 17 Jun 2022 10:35:31 -0500
Subject: [PATCH 2/4] Update README.md
---
README.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/README.md b/README.md
index afe3ca1..6b440da 100644
--- a/README.md
+++ b/README.md
@@ -9,6 +9,7 @@ Usage
Load extension using %load_ext cppmagic.
Use %%cpp at the beginning of the cell and write your C++ code. Execute to get results or compilation errors.
Use %%cpp -t to get a timeit result.
+Use %%cpp -- [-args...] to pass arguments to the C++ compiler. (For example, %%cpp -- -O3 -lpthread)
From d20e2f07b38a1e809b2d0a8071cf45c3799c3caa Mon Sep 17 00:00:00 2001
From: Justin <62445349+zenarcher007@users.noreply.github.com>
Date: Fri, 17 Jun 2022 10:39:18 -0500
Subject: [PATCH 3/4] Implement compiler arguments
Added support for compiler arguments to g++ within the cell magic declaration. Any arguments after "--" will be passed to as arguments to g++, and anything before will be passed as arguments to the cpp magic. For example, you can use "%%cpp -t -- -O3 -lpthread" at the beginning of your cell. This will run "timeit" on the cpp magic, while passing the "-O3" and "-lpthread" arguments to g++.
---
cppmagic.py | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/cppmagic.py b/cppmagic.py
index 05aa5b4..f547b28 100644
--- a/cppmagic.py
+++ b/cppmagic.py
@@ -13,6 +13,7 @@ def get_argparser():
parser = argparse.ArgumentParser(description='CppMagic params')
parser.add_argument("-t", "--timeit", action='store_true',
help='flag to return timeit result instead of stdout')
+ parser.add_argument("rest", nargs = argparse.REMAINDER)
return parser
@@ -23,8 +24,9 @@ def __init__(self, shell):
super(CppMagic, self).__init__(shell)
self.argparser = get_argparser()
- def _compile(self, file_path):
- subprocess.check_output(["g++", file_path + ".cpp", "-o", file_path + ".out"], stderr=subprocess.STDOUT)
+ def _compile(self, file_path, compilerOpts=None):
+ cmd = ["g++", file_path + ".cpp", "-o", file_path + ".out"] + compilerOpts[1:len(compilerOpts)]
+ subprocess.check_output(cmd, stderr=subprocess.STDOUT)
def _run(self, file_path, timeit=False):
if timeit:
@@ -48,7 +50,7 @@ def cpp(self, line, cell):
with open(file_path + ".cpp", "w") as f:
f.write(cell)
try:
- self._compile(file_path)
+ self._compile(file_path, compilerOpts = args.rest)
output = self._run(file_path, timeit=args.timeit)
except subprocess.CalledProcessError as e:
print(e.output.decode("utf8"))
From 9801422486907861b126a0ef5b19a0bf8766db48 Mon Sep 17 00:00:00 2001
From: Justin <62445349+zenarcher007@users.noreply.github.com>
Date: Fri, 17 Jun 2022 18:48:27 -0500
Subject: [PATCH 4/4] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 6b440da..6800b1b 100644
--- a/README.md
+++ b/README.md
@@ -8,7 +8,7 @@ Usage
--------
Load extension using %load_ext cppmagic.
Use %%cpp at the beginning of the cell and write your C++ code. Execute to get results or compilation errors.
-Use %%cpp -t to get a timeit result.
+Use %%cpp -t to get a timeit result.
Use %%cpp -- [-args...] to pass arguments to the C++ compiler. (For example, %%cpp -- -O3 -lpthread)