Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cross compilations techniques compile error #20

Closed
volker-raschek opened this issue Nov 5, 2018 · 1 comment
Closed

cross compilations techniques compile error #20

volker-raschek opened this issue Nov 5, 2018 · 1 comment

Comments

@volker-raschek
Copy link

volker-raschek commented Nov 5, 2018

I try to read out the data of my DHT11 sensor using the example. My Golang code looks like this:

package main

import (
	"fmt"
	"log"
	"os"

	"github.com/d2r2/go-dht"
)

func main() {
	temperature, humidity, err := dht.ReadDHTxx(dht.DHT11, 4, true)
	if err != nil {
		log.Fatal(err)
		os.Exit(1)
	}
	// Print temperature and humidity
	fmt.Printf("Temperature = %v*C, Humidity = %v%%\n", temperature, humidity)
}

I downloaded the lib via go get -u github.com/d2r2/go-dht.

Thereby compile the binary on my Arch Linux system. Therefore I give the ARM, OS and ARCH variables so that the binary is executable on the Pi. When compelling I get the following error:

markus@markus-pc:~/go/src/dht11-example$ GOARM=7 GOOS=linux GOARCH=arm go build
./main.go:17:32: undefined: dht.ReadDHTxx
./main.go:17:46: undefined: dht.DHT11

Does anyone have any idea what I'm doing wrong?

@d2r2
Copy link
Owner

d2r2 commented Dec 3, 2018

Hi @volker-raschek! Sorry, for delayed response.

You should remember, that since DHT library partially written in C (and your native system has no ARM7 architecture), and you employ "cross compilation techniques", so you should have on your system special cross c-compiler installed. The name of c-compiler for Debian/Ubuntu system will be arm-linux-gnueabi-gcc, for Arch Linux arm-linux-gnueabihf-gcc.

So, once you have this c-compiler, you must modify your compilation call accordingly:

  • for Debian/Ubuntu: CC=arm-linux-gnueabi-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=7|6 go build
  • for Arch Linux: CC=arm-linux-gnueabihf-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=7|6 go build

Note: you should select ARM version 6 or 7. Regular Raspberry PI ordinary has 6.

I have one on my Arch Linux notebook where i'm doing all the development (and cross compilation works good), and as I remember arch ecosystem has this compiler only in AUR repository, so you should install it from here:
https://aur.archlinux.org/packages/arm-linux-gnueabihf-gcc/

I think the hardest part here is installing a с-compiler, so try and let me know if you still need help.

@d2r2 d2r2 changed the title compile error cross compilations techniques compile error Dec 3, 2018
@d2r2 d2r2 closed this as completed Jun 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants