How to create a global pointer variable for a custom structure

I define a structure in the header file types.h:

typedef struct{
char str [10].
void *p.

In Pass, I first refer to the header file. I want to create a global pointer in pass to access the structured array

#include ".. /types.h"
static StructType *fp_type = llvm::StructType::getTypeByName(C,"for_test");
GlobalVariable *F_Pointer = new GlobalVariable(
M, PointerType::get (fp_type, 0), false,
GlobalValue::ExternalLinkage, 0, "f_p");

However, PointerType::get (fp_type,0) has an error and I don’t know how to fix it.

Including a C header in your pass doesn’t define it in the IR your pass is operating on. You need to actually create the type in the IR.

types. h is a header file that I have customized. At compile time, if only the first command to fetch the structure type was successfully passed, but the second GlobalVariable was added to generate the following error:

So I think the error should be PointerType::get(fp_type,0), but I don’t know how to fix it.

getTypeByName returned NULL because your type does not exist in the IR.

So that’s it. Thanks! I will try to create the type in th IR.