diff --git a/Cargo.lock b/Cargo.lock
index ea295fdffe60316165c2de9f8ef41d3536579039..67731f6030199a2ad7777861922d2f654fe3501b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -718,6 +718,7 @@ name = "juno_build"
 version = "0.1.0"
 dependencies = [
  "hercules_ir",
+ "hercules_rt",
  "juno_frontend",
  "with_builtin_macros",
 ]
diff --git a/hercules_opt/src/pass.rs b/hercules_opt/src/pass.rs
index a9654b06b6f8ad71ea553ebd560aa60b3ed1c34d..a8e33a38a37200031117a6c11e515a39b3ef67de 100644
--- a/hercules_opt/src/pass.rs
+++ b/hercules_opt/src/pass.rs
@@ -974,6 +974,9 @@ impl PassManager {
                     println!("{}", cuda_ir);
                     println!("{}", rust_rt);
 
+                    let output_archive = format!("{}/lib{}.a", output_dir, module_name);
+                    println!("{}", output_archive);
+
                     // Write the LLVM IR into a temporary file.
                     let tmp_dir = TempDir::new().unwrap();
                     let mut llvm_path = tmp_dir.path().to_path_buf();
@@ -999,32 +1002,36 @@ impl PassManager {
                         .expect("Error running clang. Is it installed?");
                     assert!(clang_process.wait().unwrap().success());
 
-                    // Write the CUDA IR into a temporary file.
-                    let mut cuda_path = tmp_dir.path().to_path_buf();
-                    cuda_path.push(format!("{}.cu", module_name));
-                    let mut file = File::create(&cuda_path)
-                        .expect("PANIC: Unable to open output CUDA IR file.");
-                    file.write_all(cuda_ir.as_bytes())
-                        .expect("PANIC: Unable to write output CUDA IR file contents.");
+                    let mut ar_args = vec!["crus", &output_archive, &llvm_object];
 
                     let cuda_object = format!("{}/{}_cuda.o", tmp_dir.path().to_str().unwrap(), module_name);
-                    let mut nvcc_process = Command::new("nvcc")
-                        .arg("-c")
-                        .arg("-O3")
-                        .arg("-o")
-                        .arg(&cuda_object)
-                        .arg(&cuda_path)
-                        .spawn()
-                        .expect("Error running nvcc. Is it installed?");
-                    assert!(nvcc_process.wait().unwrap().success());
+                    if cfg!(feature = "cuda") {
+                        // Write the CUDA IR into a temporary file.
+                        let mut cuda_path = tmp_dir.path().to_path_buf();
+                        cuda_path.push(format!("{}.cu", module_name));
+                        let mut file = File::create(&cuda_path)
+                            .expect("PANIC: Unable to open output CUDA IR file.");
+                        file.write_all(cuda_ir.as_bytes())
+                            .expect("PANIC: Unable to write output CUDA IR file contents.");
+
+                        let mut nvcc_process = Command::new("nvcc")
+                            .arg("-c")
+                            .arg("-O3")
+                            .arg("-lcudart")
+                            .arg("-L/usr/lib/x86_64-linux-gnu")
+                            .arg("-L/usr/local/cuda/lib64")
+                            .arg("-o")
+                            .arg(&cuda_object)
+                            .arg(&cuda_path)
+                            .spawn()
+                            .expect("Error running nvcc. Is it installed?");
+                        assert!(nvcc_process.wait().unwrap().success());
+
+                        ar_args.push(&cuda_object);
+                    }
 
-                    let output_archive = format!("{}/lib{}.a", output_dir, module_name);
-                    println!("{}", output_archive);
                     let mut ar_process = Command::new("ar")
-                        .arg("crus")
-                        .arg(&output_archive)
-                        .arg(&llvm_object)
-                        .arg(&cuda_object)
+                        .args(&ar_args)
                         .spawn()
                         .expect("Error running ar. Is it installed?");
                     assert!(ar_process.wait().unwrap().success());
diff --git a/hercules_rt/build.rs b/hercules_rt/build.rs
index 15b9f6396d2c90eee66dfecb5a255cef2890726b..6db177de459db63a9a2cb173cf719a912573d352 100644
--- a/hercules_rt/build.rs
+++ b/hercules_rt/build.rs
@@ -18,6 +18,7 @@ fn main() {
 
         println!("cargo::rustc-link-search=native={}", out_dir);
         println!("cargo::rustc-link-search=native=/usr/lib/x86_64-linux-gnu/");
+        println!("cargo:rustc-link-search=native=/usr/local/cuda/lib64");
         println!("cargo::rustc-link-lib=static=rtdefs");
         println!("cargo::rustc-link-lib=cudart");
         println!("cargo::rerun-if-changed=src/rtdefs.cu");
diff --git a/juno_build/Cargo.toml b/juno_build/Cargo.toml
index 138891710760e547fe743e31c814080002a71011..67b5bd7ecf0440185d97a8e53c0cf0b38262f26d 100644
--- a/juno_build/Cargo.toml
+++ b/juno_build/Cargo.toml
@@ -5,9 +5,10 @@ authors = ["Aaron Councilman <aaronjc4@illinois.edu>"]
 edition = "2021"
 
 [features]
-cuda = ["juno_frontend/cuda"]
+cuda = ["juno_frontend/cuda", "hercules_rt/cuda"]
 
 [dependencies]
 juno_frontend = { path = "../juno_frontend" }
+hercules_rt = { path = "../hercules_rt", optional = true }
 hercules_ir = { path = "../hercules_ir" }
 with_builtin_macros = "0.1.0"