# Calling Numba program in C++ compilation steps

**URL:** <https://numba.discourse.group/t/calling-numba-program-in-c-compilation-steps/3067>\
**Category:** Development\
**Created:** [October 2, 2025, 4:32am UTC](https://numba.discourse.group/t/calling-numba-program-in-c-compilation-steps/3067 "2025-10-02T04:32:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![evso98](https://avatars.discourse-cdn.com/v4/letter/e/858c86/32.png) [@evso98](https://numba.discourse.group/u/evso98)\
**Post date:** [October 2, 2025, 4:32am UTC](https://numba.discourse.group/t/calling-numba-program-in-c-compilation-steps/3067/1 "2025-10-02T04:32:45Z")

</div>

First step: obtain LLVM IR files  
I built a simple numba program, compiled it with “numba –dump-llvm numba\_file.py \> numba\_file.ll“ to obtain an IR _file1.  
I also built a simple C++ program that calls the function defined in numba. I compiled the C++ program using “clang+±20 ….“ to obtain another IR_ file2.  
Second step: convert/combine LLVM IR to bitecode (\*.bc):  
I used “llvm-link-20 file1.ll file2.ll to\_somefile.bc“

Problem: I have a versioning problem between file1.ll and file2.ll and can’t pass step 2. Installation information: LLVM-20; llvmlite 0.45; numba 0.62. Numba 0.45 has been installed in reference to llvmlite 0.45, which in turn refers to LLVM-20.

Questions: 1) how may I link explicitely numba compilation step to LLVM-20?  
2) Are there ways to eliminate versioning problems between numba IR and C++ IR in second step?  
3) Any other hint would be appreciated: calling numba program in C++. Thanks.

---

<div class="post-metadata">

**Author:** ![milton](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@milton](https://numba.discourse.group/u/milton)\
**Post date:** [October 2, 2025, 1:14pm UTC](https://numba.discourse.group/t/calling-numba-program-in-c-compilation-steps/3067/2 "2025-10-02T13:14:15Z")

</div>

I have something similar [here](https://github.com/Goykhman/discourse/tree/main/export_llvm). It works on my mac, with [these](https://github.com/Goykhman/discourse/blob/main/requirements.txt) requirements.

---

<div class="post-metadata">

**Author:** ![evso98](https://avatars.discourse-cdn.com/v4/letter/e/858c86/32.png) [@evso98](https://numba.discourse.group/u/evso98)\
**Post date:** [October 3, 2025, 2:31am UTC](https://numba.discourse.group/t/calling-numba-program-in-c-compilation-steps/3067/3 "2025-10-03T02:31:05Z")

</div>

Thanks for the input. I’ll explore your solution further and keep you updated.

Quick question: how did you obtain this long chain in the \*.h file? “cfunc\_ZN8\_\_main\_\_11calculationB2v1B52c8tJTIeFIjxB2IKSgI4CrvQClUYkACQB1EiFSRRB9GgCAA\_3d\_3dE10float64\_2a10float64\_2ad(double\* , double\* , double )“?  
Is after compiling the source.py with numba to IR file? I’ll appreciate it if you could give me more steps/hints.

What did you use to compile the C++ program? gcc, clang, etc. (any hint will be appreciated). Thanks.

---

<div class="post-metadata">

**Author:** ![milton](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@milton](https://numba.discourse.group/u/milton)\
**Post date:** [October 3, 2025, 11:22am UTC](https://numba.discourse.group/t/calling-numba-program-in-c-compilation-steps/3067/4 "2025-10-03T11:22:51Z")

</div>

Yes you’re correct, the long mangled `cfunc…` name in calcilation.h and main.cpp is the name that numba creates for the `calculation` function that it compiles in main.py.

If you run make, you it will (in particular) [produce](https://github.com/Goykhman/discourse/blob/main/export_llvm/Makefile#L57) calculation.ll that will contain the LLVM IR code for that function. You can verify that the same named `cfunc…` function is defined there.

(I suppose a programmatic way of generating that name is accessible using the same [mangler](https://github.com/numba/numba/blob/main/numba/core/itanium_mangler.py#L190) that numba is using.)

I compiled this on my mac with [clang](https://github.com/Goykhman/discourse/blob/main/export_llvm/Makefile#L5)/[llvm20](https://github.com/Goykhman/discourse/blob/main/export_llvm/Makefile#L6).

My demo also includes creating a shared lib out of ‘another\_calculation‘ (besides the static object file compiled from the ‘calculation‘ and linked to the main program). You can ignore it for your purposes.

You can run the demo via the `make run` command. (It will give the path to numba’s NRT shared lib as an argument to the main executable.)

---

<div class="post-metadata">

**Author:** ![nelson2005](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/nelson2005/32/47_2.png) [@nelson2005](https://numba.discourse.group/u/nelson2005)\
**Post date:** [October 3, 2025, 1:23pm UTC](https://numba.discourse.group/t/calling-numba-program-in-c-compilation-steps/3067/5 "2025-10-03T13:23:48Z")

</div>

Is the goal simply to call numba code from c++? Or the goal is to call numba code from c++ using LLVM IR?

---

<div class="post-metadata">

**Author:** ![evso98](https://avatars.discourse-cdn.com/v4/letter/e/858c86/32.png) [@evso98](https://numba.discourse.group/u/evso98)\
**Post date:** [October 3, 2025, 4:29pm UTC](https://numba.discourse.group/t/calling-numba-program-in-c-compilation-steps/3067/6 "2025-10-03T16:29:19Z")

</div>

The goal is to call numba code from c++ using LLVM IR. However, your proposed solution is a good biginning. I will explore that, make few changes and let you know how it goes. Thanks so much for your input. It’s a good subject.
