Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

llvm InitializeNativeTarget() is undefined

Tags:

c++

llvm

clang

All of the samples I'm seeing show llvm::InitializeNativeTarget() being called on the first line.

I just finished building llvm and clang and am trying to get my first sample running and this function appears to be undefined. I'm not sure if it is actually undefined and these examples are stale, or if I did something wrong in a previous step.

Where would I find the definition of this function if it is supposed to exist? Is there something else I should be calling instead?

InitializeNativeTarget(); /* error, undefined */
llvm_start_multithreaded();
LLVMContext context;
string error;
llvm::OwningPtr<MemoryBuffer> buffer;

auto result = MemoryBuffer::getFile("test.bc", buffer);
auto m = ParseBitcodeFile(buffer.get(), context, &error);
auto ee = ExecutionEngine::create(m, true, &error);

With the code above, and a test.bc file compiled via clang I am getting a null ExecutionEngine so I'm assuming I'm not initializing something correctly.

like image 582
justin.m.chase Avatar asked Jan 22 '26 09:01

justin.m.chase


2 Answers

Surprisingly hard to find but the function appears to have been renamed to:

LLVMInitializeNativeTarget()

Simply calling that function solved my problem.

(also I needed to call ExecutionEngine::create(m, false, &error) instead of true)

like image 125
justin.m.chase Avatar answered Jan 25 '26 00:01

justin.m.chase


This is just a clarification. Actually, function llvm::InitializeNativeTarget can be found in

#include "llvm/Support/TargetSelect.h"

Your called function llvm::LLVMInitializeNativeTarget exists in

#include "llvm-c/Target.h"

The latter header file is already included by ExecutionEngine.h. Therefore you found it. Both functions seem identical (until v3.9.1 at least) except for their return value. However, the former is the one used in LLVM examples and I'd recommend sticking with it especially if you are using C++.

like image 39
Codoka Avatar answered Jan 25 '26 00:01

Codoka