Segment Error occured as call a function in go from C++

with g++ 9.3.0 & go 1.10.4

I want to call a go function to let it print an integer input by C++.

Here is the setup:

In go:

//export OnLogin_1
func OnLogin_1(status C.int) {
	fmt.Println("target1 ok:", status)
}

In the header file:

typedef void (*nfun)(int LoginStatus);
extern nfun OnLogin_1;

This tells that the there is a function called OnLogin_1 and it has one argument as integer

Then in cpp file:

std::cout << "=====Login Succeeded @" << this->target << std::endl;
if(this->target==1)          OnLogin_1(1);

I saw the print out =====Login Succeeded @1
And the next line: Segment Error

What is wrong with my code? Thanks in advance.

What’s the command you’re using to build your Go code?

just simply go build in the code directory, to compile all the scripts inside it rather than a single file.