I’ve created a package logging
with the following contents:
package logging
/*
#cgo LDFLAGS: -L. -L../lib -lcfastlogging
#include "../lib/gofastlogging.h"
*/
import "C"
const DEBUG = 10
type Logging struct {
logging C.Logging
}
func Init() Logging {
logging := C.logging_init()
instance := Logging{logging}
return instance
}
func (instance Logging) debug(message string) {
C.logging_debug(instance.logging, C.CString(message))
}
In the main package I’m using it as follows:
package main
import "examples/logging"
func main() {
logger := logging.Init()
logger.debug("Debug message")
}
go.mod
has following contents:
module examples
go 1.22.3
The file structure is:
examples/example/main.go
logging/logging.go
lib/gofastlogging.h
go.mod
The problem now is that go
prints the following error when I want to execute main.go
:
examples/example/main.go:8:9: logger.debug undefined (type logging.Logging has no field or method debug)
Why is the method debug
not a method of the struct Logging
? I’ve done it exactly how it is described in the tutorials.