Generating a call to c++ STL function in IR?

Hello :slight_smile: ,

I’m trying to generate LLVM-IR that calls a function from C++ STL (e.g. std::sort() ) .

I need to perform the following steps.

  1. Check whether std::sort() is available in the build environment.
  2. Create a call to std::sort() using IRBuilder.CreateCall()

May I ask for advice on how to perform the 1st step above?
Thank you :rocket:

std::sort, like most STL function can’t be just “available in the build environment”: these are templated functions that needs to be instantiated for C++ types, and then dispatch to a comparison operator that depends on the C++ types.
You would have better chance looking for C-library level functions, like qsort.

1 Like

@JOE1994 , @mehdi_amini

I want to call a c or c++ function in LLVM IR. Do you have any idea about that? I’d appreciate it if you can provide an example.


This looks like a duplicate of How to call c++ code in LLVM IR.