jjcarstens / dht

Elixir implementation to read DHT11 and DHT22 sensors
Apache License 2.0
17 stars 1 forks source link

Not compiling on Mac OS host machine #5

Closed mnishiguchi closed 3 years ago

mnishiguchi commented 3 years ago

Maybe this is a known issue, but I'll report it just in case anybody has the same issue.

As I quickly googled, Mac does not have the sched_setscheduler function, which is called in src/common_dht_read.c.

As a workaround, I only compiled the library for my target device:

# Dependencies for all targets except :host
{:dht, "~> 0.1", targets: @all_targets},

Here is the error I got on my Mac:

nerves_hello_lcd via 💧 1.11.2 (OTP 23)
❯ mix test
===> Compiling telemetry
===> Compiling telemetry_poller
==> dht
mkdir -p /Users/mnishiguchi/src/nerves_hello_lcd/_build/test/lib/dht/ebin/../obj
mkdir -p /Users/mnishiguchi/src/nerves_hello_lcd/_build/test/lib/dht/ebin/../priv
cc -D TARGET=1 -c -I/usr/local/Cellar/erlang/23.1.1/lib/erlang/usr/include -O2 -Wall -Wextra -Wno-unused-parameter -Werror -std=gnu99 -o /Users/mnishiguchi/src/nerves_hello_lcd/_build/test/lib/dht/ebin/../obj/main.o src/main.c
cc -D TARGET=1 -c -I/usr/local/Cellar/erlang/23.1.1/lib/erlang/usr/include -O2 -Wall -Wextra -Wno-unused-parameter -Werror -std=gnu99 -o /Users/mnishiguchi/src/nerves_hello_lcd/_build/test/lib/dht/ebin/../obj/erlcmd.o src/erlcmd.c
cc -D TARGET=1 -c -I/usr/local/Cellar/erlang/23.1.1/lib/erlang/usr/include -O2 -Wall -Wextra -Wno-unused-parameter -Werror -std=gnu99 -o /Users/mnishiguchi/src/nerves_hello_lcd/_build/test/lib/dht/ebin/../obj/pi_dht_read.o src/pi_dht_read.c
cc -D TARGET=1 -c -I/usr/local/Cellar/erlang/23.1.1/lib/erlang/usr/include -O2 -Wall -Wextra -Wno-unused-parameter -Werror -std=gnu99 -o /Users/mnishiguchi/src/nerves_hello_lcd/_build/test/lib/dht/ebin/../obj/pi_mmio.o src/pi_mmio.c
cc -D TARGET=1 -c -I/usr/local/Cellar/erlang/23.1.1/lib/erlang/usr/include -O2 -Wall -Wextra -Wno-unused-parameter -Werror -std=gnu99 -o /Users/mnishiguchi/src/nerves_hello_lcd/_build/test/lib/dht/ebin/../obj/common_dht_read.o src/common_dht_read.c
src/common_dht_read.c:51:12: error: implicit declaration of function 'clock_nanosleep' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    while (clock_nanosleep(CLOCK_MONOTONIC, 0, &sleep, &sleep) && errno == EINTR);
           ^
src/common_dht_read.c:60:5: error: implicit declaration of function 'sched_setscheduler' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    sched_setscheduler(0, SCHED_FIFO, &sched);
    ^
src/common_dht_read.c:69:5: error: implicit declaration of function 'sched_setscheduler' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    sched_setscheduler(0, SCHED_OTHER, &sched);
    ^
3 errors generated.
make: *** [/Users/mnishiguchi/src/nerves_hello_lcd/_build/test/lib/dht/ebin/../obj/common_dht_read.o] Error 1
could not compile dependency :dht, "mix compile" failed. You can recompile this dependency with "mix deps.compile dht", update it with "mix deps.update dht" or clean it with "mix deps.clean dht"
==> nerves_hello_lcd
** (Mix) Could not compile with "make" (exit status: 2).
You need to have gcc and make installed. Try running the
commands "gcc --version" and / or "make --version". If these programs
are not installed, you will be prompted to install them.
jjcarstens commented 3 years ago

@mnishiguchi thanks! Can you give me more details about the setup that caused this? MacOS is working for me locally when compiling for host because it detects that its host and puts some mock behavior in.

However, in your setup it is trying to compile for rpi without the cross compile tools. What is you MIX_TARGET set to?

mnishiguchi commented 3 years ago

@jjcarstens Maybe it was because I ran mix test, which is a habit I have. Looks like mix compile works with no issue on the Mac host.

The above error happens whenever I run mix test.

My OS and target:

Screen Shot 2020-12-23 at 12 08 48 PM

❯ echo $MIX_TARGET
rpi0
mnishiguchi commented 3 years ago

@jjcarstens I looked at main.c. I do not know details but I see rpi0 unsupported. Despite that, thankfully I was at least able to read the sensor data from DHT11.

jjcarstens commented 3 years ago

So rpi0 is supported. The rpi support is sort of lumped into 2 different "hardware" version. RPI, which is rpi and rpi0 in a nerves context, and RPI2, which is rpi2 and above (rpi3, rpi3a, rpi4)

This is left over from the arduino C code. I don't love it, but haven't spent the time to change it yet either.

You can also see this in the Makefile definitions as well

jjcarstens commented 3 years ago

Going to close this for now. I can reproduce with MIX_TARGET=rpi0 mix test which is expected because it attempts to compile RPI src for the DHT and then run it on host. I think the simplest fix here is to ensure you run tests under HOST and not the target.