d2r2 / go-dht

Golang library to interact with DHT11/DHT22/DHT12 temperature and humidity sensors from Raspberry PI.
MIT License
133 stars 52 forks source link

Installation failure on macOS #11

Open limoli opened 6 years ago

limoli commented 6 years ago

As documentation, I executed: go get -u github.com/d2r2/go-dht

# github.com/d2r2/go-dht
In file included from ../../go/src/github.com/d2r2/go-dht/dht.go:3:
../../go/src/github.com/d2r2/go-dht/dht.go.h:304:15: warning: implicit declaration of function 'sched_setscheduler' is invalid in C99 [-Wimplicit-function-declaration]
# github.com/d2r2/go-dht
ld: library not found for -lrt
clang: error: linker command failed with exit code 1 (use -v to see invocation)
d2r2 commented 5 years ago

Hi @Limoli! Could you clarify what hardware and OS you use to download and compile package? Just it seems you have CLANG compiler installed only, but I test it with GCC compiler on Linux OS.

Additional assumption you need to install ld tool (GNU linker from "binutils" installation distributive). I will try to test compiling without GCC in virtual environment a little later.

Sorry for late response.

ghost commented 5 years ago

same issue on mac os mojave

$ go get -u github.com/d2r2/go-dht ld: library not found for -lrt clang: error: linker command failed with exit code 1 (use -v to see invocation) In file included from ../../d2r2/go-dht/dht.go:3: ../../d2r2/go-dht/dht.go.h:304:15: warning: implicit declaration of function 'sched_setscheduler' is invalid in C99 [-Wimplicit-function-declaration] ../../d2r2/go-dht/dht.go.h:317:15: warning: implicit declaration of function 'sched_setscheduler' is invalid in C99 [-Wimplicit-function-declaration]

d2r2 commented 5 years ago

Could you clarify, why you are trying to compile this library directly on MacOS? This library is intended to compile and use on embedded Linux devices, like Raspberry PI, Orange PI, Banana PI and so on.

ghost commented 5 years ago

Using go cross compilation for arm-6, linux. Idea was to deploy already executable item to raspberry pi.

d2r2 commented 5 years ago

Hi @darkowl91! Could you try again to get latest d2r2/go-dht and cross compile it? Just recently I have added a fix for macOS. P.S. I'm not sure that cross compilation will work from macOS, but lets try...

pradyuz3rocool commented 5 years ago

@d2r2 THe latest fix for macOS is not working . Just informing. As i am also gettgint he same error as @darkowl91

d2r2 commented 5 years ago

Hi @pradyuz3rocool! Could you attach here compilation output with error from macOS?

pradyuz3rocool commented 5 years ago
apple@iSteers-MacBook-Pro-Pradyu ~ $ go get -u github.com/d2r2/go-dht
# github.com/d2r2/go-dht
ld: library not found for -lrt
clang: error: linker command failed with exit code 1 (use -v to see invocation)
# github.com/d2r2/go-dht
In file included from go-workspace/src/github.com/d2r2/go-dht/dht.go:24:
go-workspace/src/github.com/d2r2/go-dht/dht.go.h:428:10: warning: "Darwin doesn't have sched_setscheduler, so parameter boostPerfFlag is useless on Apple devices" [-W#warnings]
go-workspace/src/github.com/d2r2/go-dht/dht.go.h:434:9: warning: implicit declaration of function 'set_default_priority' is invalid in C99 [-Wimplicit-function-declaration]
go-workspace/src/github.com/d2r2/go-dht/dht.go.h:440:9: warning: implicit declaration of function 'set_default_priority' is invalid in C99 [-Wimplicit-function-declaration]
go-workspace/src/github.com/d2r2/go-dht/dht.go.h:446:9: warning: implicit declaration of function 'set_default_priority' is invalid in C99 [-Wimplicit-function-declaration]
go-workspace/src/github.com/d2r2/go-dht/dht.go.h:454:9: warning: implicit declaration of function 'set_default_priority' is invalid in C99 [-Wimplicit-function-declaration]
go-workspace/src/github.com/d2r2/go-dht/dht.go.h:462:9: warning: implicit declaration of function 'set_default_priority' is invalid in C99 [-Wimplicit-function-declaration]
go-workspace/src/github.com/d2r2/go-dht/dht.go.h:470:9: warning: implicit declaration of function 'set_default_priority' is invalid in C99 [-Wimplicit-function-declaration]
go-workspace/src/github.com/d2r2/go-dht/dht.go.h:475:9: warning: implicit declaration of function 'set_default_priority' is invalid in C99 [-Wimplicit-function-declaration]
d2r2 commented 5 years ago

@pradyuz3rocool, thank you for reporting that issue still present! Main problem is that unfortunately I have no macOS system in my hands. I do all my development on Arch Linux system either directly on Raspberry PI linux. So, in both cases everything works great, but I have no chance to build DHT library on macOS. I will try to get in my hands macOS, but I don’t promise to do it quickly :(

Until this problem is fixed, my advice is to compile directly on Raspberry PI device, or any corresponding clones.

pradyuz3rocool commented 5 years ago

Thanks @d2r2 I myself work on Arch, but i was trying the same implementation on macOS, i was facing this issue. But Would love to make it generic. I will also look into the fix in the mean while.

d2r2 commented 5 years ago

@pradyuz3rocool, I thought we have two concerns about macOS: 1) macOS has no sched_setscheduler() function. So that's why I put calls of set_max_priority() and set_default_priority() in #ifdef block like:

    #if !defined(__APPLE__)
    ...
    #endif

But as I see, I forget to do this with bunch of set_default_priority()calls - you can fix it.

2) I don't know what to do with error ld: library not found for -lrt and since linux use gcc compiler (macOS - clang), you should try to find approach how to modify this in dht.go:

// #include "dht.go.h"
// #cgo LDFLAGS: -lrt

to make it working on both systems.

Try and give me reply how it's going.

pradyuz3rocool commented 5 years ago

Sure 👍 will look into it

ghost commented 5 years ago

@pradyuz3rocool any luck with this ?

ghost commented 5 years ago

Was able to build on mac with the following settings

#export GOARM=6 GOARCH=arm GOOS=linux CGO_ENABLED=1
#env CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ \
#    CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=6 \
d2r2 commented 5 years ago

@darkowl91, in this case compile line for mac OS will looks like:

CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=6 go build ...

Is it correct?

ghost commented 4 years ago

yes