Import Non Standard C++ Lib Using Import "C"

You need to tell cgo where to look. Here’s a snippet extracted from some of my code to give you an idea:

/*
#cgo windows CFLAGS: -DTAG_WINDOWS
#cgo linux freebsd CFLAGS: -DTAG_POSIX
#cgo linux freebsd LDFLAGS: -ldl
#cgo CFLAGS: -I ${SRCDIR}/sdk/samples/common/inc

CFLAGS, CPPFLAGS, CXXFLAGS, FFLAGS and LDFLAGS may be defined with pseudo #cgo directives within these comments to tweak the behavior of the C, C++ or Fortran compiler.

1 Like