I am trying to compile go project in raspberry pi.
There are 5 files in the project, two small .c files and its associations .h (one of these files is my code - it calls the other, which is the base of the .go ) and .go files that call my .c with cgo .
When I compile only my C code (with my calls and everything) with gcc only in raspberry pi, it does fine without any configuration.
When I compile the whole go project on my x86 Linux Ubuntu computer with go build , it also works very well.
But when I try to compile the go project with go build in raspberry pi, it does not get my C libraries:
fiatjaf@raspberrypi ~/g/s/b/f/project> go build -x WORK=/tmp/go-build702187084 mkdir -p $WORK/bitbucket.org/fiatjaf/project/_obj/ cd /home/fiatjaf/go/src/bitbucket.org/fiatjaf/project /usr/lib/go/pkg/tool/linux_arm/5c -FVw -I $WORK/bitbucket.org/fiatjaf/project/_obj/ -I /usr/lib/go/pkg/linux_arm -o $WORK/bitbucket.org/fiatjaf/project/_obj/base64.5 -DGOOS_linux -DGOARCH_arm ./base64.c
(If I put <stdlib.h> in front of <math.h> , the problem also arises for him, so the problem is not the absence of math.h, I think) I tried:
- add
// #cgo CFLAGS: -I/usr/include to the .go file - add
// #cgo LDFLAGS: -I/usr/include (I cannot find out what the proper use of these flags is) - use
go build -ldflags '-I/usr/include'
I do not understand why go is trying to compile base64.c with -I /usr/lib/go/pkg/linux_arm . Not really. Someone will help.
EDIT: Clarification Note on Project Structure:
It has 5 files, 2 C (and its mapping H):
base64.c
#include <math.h> #include <stdint.h> #include <stdlib.h> ... // definitions of functions used at project.c
project.c
#include <stdlib.h> #include <string.h> #include "base64.h" ... // functions used at project.go
and 1 Go:
... // #include <stdlib.h> // #include <string.h> // #include "project.h" // #cgo CFLAGS: -I/usr/include // #cgo LDFLAGS: -lm import "C" ...
Where, what, and how do I change these declarations to make this thing work? And why did this work for my x86-Linux?
arm go raspberry-pi cgo
fiatjaf
source share