I have some Go code and some C code (quite a bit really). I am calling the C code from the go code. Here is an example:
test.h
#ifndef TEST_H
#define TEST_H
void test();
#endif
test.c
#include "test.h"
#include <stdio.h>
void test() {
printf("Hello from C!")
}
main.go
package main
// #include "test.h"
import "C"
import "fmt"
func main() {
C.test()
}
Imagine I have much more C code. This C code takes a while to compile. When compiling using go build
, it recompiles the C every time. Is it possible to compile the C and go separately? Meaning that if I am working on the Golang code, I won't have to compile to C code?
I have tried linking the object files, but it seems very inefficient. If this is the best option? If so, could you provide a code example showing me how (as my way only works on Linux).