Can we pass a Map(Unordered Map) from cpp to go , Initialize it there and send it back to cpp

I’m trying to pass a a unordered_map from cpp to golang and vice-versa. I have compiled the golang code as a dll(I’m using windows) with header file and created a lib file for it. I’m including the header in cpp and linking the library. When I’m using the method, it is throwing a error.

The GoLang code is as follows
func Initialize(m *map[*C.char]*C.char) {
ctr1 := C.CString(“MyName”)
ctr2 := C.CString(“1”)
(*m)[ctr1] = ctr2

The CPP code is as follows
std::unordered_map<char*, char*> *mapInstance;
Initialize((void **)&mapInstance);

The Header File included has
typedef void GoMap;
extern void Initialize(GoMap

The error thrown is

panic: assignment to entry in nil map

goroutine 17 [running, locked to thread]:
D:/GoLang/Learning/Map/Return_Map/MapReturn.go:10 +0x95
_cgo_gotypes.go:61 +0x32

Please Help me in the right direction.


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.