Search code examples
gocgo

How to let Go find library headers?


I've been searching for a while but cannot find a solution to this issue.

Because libraries like SDL2 are not part of the OpenBSD operating system, they are stored in /usr/local. Go seems to be looking for headers in /usr/include and not /usr/local/include. I see flags in go env but I'm unable to edit them.

Is there a way to resolve this issue without symlinks? Perhaps a Go equivalent of the -I flag common in C compilers?


Solution

  • If you're using Cgo, you must use something like this:

    /*
    #cgo CFLAGS: -I/usr/local/ssl/include
    #cgo LDFLAGS: -lcrypto -L/usr/local/ssl/lib
    */
    import "C"
    

    In this case I'm using it to compile against the latest OpenSSL. Edit to suit your needs.