clangread-eval-print-loop

How to invoke a function stored in a static library from clang-repl


Is there a mechanism that lets user to invoke a function stored in a static/archive library from clang-repl?

"%lib" magic only recognizes dynamic libraries. I further tried to utilize several link options of clang (such as "clang -lmylib.a") while calling clang-repl (i.e. clang-repl -lmylib.a"). However clang-repl always returns unknown option error for such clang options.


Solution

  • "--Xcc" option of clang-repl can be used for this purpose. Each compiler and linker option/argument of clang can be provided to clang-repl by setting Xcc argument to the corresponding option/argument string.

    One weird thing to note is that each clang option must be provided to clang-repl via a seperate Xcc option. For instance, to set 2 different include paths one must use clang-repl --Xcc=-Ifolder1 --Xcc=-Ifolder2.

    Once the path to the libraries, link commands and necessary header file locations are thus provided to clang-repl using this mechanism, any function from the static library can be directly called within the repl.