Hi Tao,
I think this question would be better suited for the llvm-dev mailing
list:
https://lists.llvm.org/mailman/listinfo/llvm-dev
Thanks,
Hans
On Wed, Jul 18, 2018 at 5:12 AM, Tao Peng <
dev.p...@gmail.com> wrote:
> Hi all,
>
> I am a newer of clang and llvm. I used llvm to code-gen, but I encounter a
> problem.
>
> I have a class as below:
>
> class AAA {
> public:
> template<typename Type>
> void func(Type str) {
> std::cout << str << std::endl;
> }
>
> void func2() {
> std::cout << "hello" << std::endl;
> }
> };
>
>
> And I have a llvm::ExecutionEngine* mJit;
>
> Now I want to use `addGlobalMapping` to add the `AAA::func` and `AAA::func2`
> to the llvm's global mapping.
>
>
> // success
> mJit->addGlobalMapping(fn_func2, reinterpret_cast<void*>(&AAA::func2));
>
> // failed
> // Because the `AAA::func` is an template function
> mJit->addGlobalMapping(fn_func, reinterpret_cast<void*>(&AAA::func));
>
>
> And then I tried one method as follow:
>
>
> template<class Class, typename K>
> using TemplateFunc = void (Class::*) (K);
>
> TemplateFunc<AAA, int> myFunc = &AAA::func;
> mJit->addGlobalMapping(fn_func, reinterpret_cast<void*>(myFunc));
>
>
> But it came an error when link:
>
> Llvm::Finalize(): error: undefined reference to "void AAA::func<int>(int)".
> collect2: error: ld returned 1 exit status
>
>
> So how to add a c++ template function to the llvm JIT global mapping ?
>
> Thanks so much.