I'm writing an LLVM pass which modifies the LLVM IR code. However, I am having trouble inserting global variables. For example, when I try to insert a global variable using the following code.<div><br></div><div><div>llvm::Value *val = new llvm::GlobalVariable(mod, llvm::Type::getInt32Ty(mod.getContext()), </div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>false, llvm::GlobalValue::ExternalLinkage, 0, "myvar");</div></div><div><br></div><div>I get the following error.</div><div><br></div><div><div>
opt: symbol lookup error: /home/hmushtaq/llvm/Debug+Asserts/lib/Basic3.so: undefined symbol: _ZN4llvm14GlobalVariableC1ERNS_6ModuleEPNS_4TypeEbNS_11GlobalValue12LinkageTypesEPNS_8ConstantERKNS_5TwineEPS0_bj</div><div>/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 0 has invalid symbol index 11</div>
<div>/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 1 has invalid symbol index 12</div><div>........</div></div><div><br></div><div>What is going on here?</div>