1

I'm trying to create a go program and I need to use freetype, but module for freetype in go seems really different from the original freetype library for c. Overcome this problem I created a simple library in C, and I'm trying to call a function in that library from Go using cgo. But I couldn't seem to figure out where should my .a file needs to be located in order go to be able to find it. I'm using go modules and my project is not in the GOPATH.

So my question is where I need to put my C library's .h and .a files?

1 Answer 1

1

If i got you right. It's a problem that you don't know how to tell cgo tool chain where to find .h and .a files. There is many examples on web, provide mine here.

code_example

package democgo

/*
#cgo CFLAGS: -I ${directory_of_your_dot_H}
#cgo LDFLAGS: -L ${directory_of_your_dot_A} -l${your_dot_A_name} -lstdc++
#include "code_from_c.h"
#include <stdlib.h>
*/
import "C"

// Hello is.
func Hello() {
    fmt.Println("this is CGO at package democgo")
    fmt.Println(
        C.GoString(
            C.HelloWorld(),
        ),
    )
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.