cgo: add support for CFLAGS in .c files

This patch adds support for passing CFLAGS added in #cgo lines of the
CGo preprocessing phase to the compiler when compiling C files inside
packages. This is expected and convenient but didn't work before.
This commit is contained in:
Ayke van Laethem
2021-03-12 17:47:06 +01:00
committed by Ron Evans
parent 896a848001
commit 1bed192de0
9 changed files with 38 additions and 25 deletions
+4
View File
@@ -5,6 +5,7 @@ int fortytwo(void);
#include "main.h"
int mul(int, int);
#include <string.h>
#cgo CFLAGS: -DSOME_CONSTANT=17
*/
import "C"
@@ -118,6 +119,9 @@ func main() {
// Check that enums are considered the same width in C and CGo.
println("enum width matches:", unsafe.Sizeof(C.option2_t(0)) == uintptr(C.smallEnumWidth))
// Check whether CFLAGS are correctly passed on to compiled C files.
println("CFLAGS value:", C.cflagsConstant)
// libc: test whether C functions work at all.
buf1 := []byte("foobar\x00")
buf2 := make([]byte, len(buf1))