pigpio
pigpio copied to clipboard
CROSS_PREFIX not always set from CLI
Recently, I had to try cross-compiling pigpio in a github CI workflow, but I didn't want to bother modifying the Makefile. According to the Makefile: https://github.com/joan2937/pigpio/blob/c33738a320a3e28824af7807edafda440952c05d/Makefile#L2-L4
I thought that by setting an env var CROSS_PREFIX
I wouldn't have to modify the Makefile, but that approach didn't take at all.
Then I tried make lib CROSS_PREFIX='arm-linux-gnueabihf-'
, and that seemed to work until it executed
https://github.com/joan2937/pigpio/blob/c33738a320a3e28824af7807edafda440952c05d/Makefile#L59-L60
as if $(CC)
was set to gcc
(without using the CROSS_PREFIX
).
Would using
CROSS_PREFIX ?= ''
be more applicable with no side-effects to typical expected usage (which I assume means modify the Makefile).
Here is the CI step used in the github workflow
- name: provide pigpio
run: |
git clone https://github.com/joan2937/pigpio.git
cd pigpio
git fetch --tags
latestTag=$(git describe --tags `git rev-list --tags --max-count=1`)
git checkout $latestTag
make lib CROSS_PREFIX='arm-linux-gnueabihf-'
sudo make install
Here is the Makefile's output
arm-linux-gnueabihf-gcc -I /usr/local/include -O3 -Wall -pthread -fpic -c -o pigpio.o pigpio.c
arm-linux-gnueabihf-gcc -I /usr/local/include -O3 -Wall -pthread -fpic -c -o command.o command.c
arm-linux-gnueabihf-gcc -shared -pthread -Wl,-soname,libpigpio.so.1 -o libpigpio.so.1 pigpio.o command.o
ln -fs libpigpio.so.1 libpigpio.so
arm-linux-gnueabihf-strip --strip-unneeded libpigpio.so
arm-linux-gnueabihf-size libpigpio.so
text data bss dec hex filename
226387 6128 605780 838295 cca97 libpigpio.so
arm-linux-gnueabihf-gcc -I /usr/local/include -O3 -Wall -pthread -fpic -c -o pigpiod_if.o pigpiod_if.c
arm-linux-gnueabihf-gcc -shared -pthread -Wl,-soname,libpigpiod_if.so.1 -o libpigpiod_if.so.1 pigpiod_if.o command.o
ln -fs libpigpiod_if.so.1 libpigpiod_if.so
arm-linux-gnueabihf-strip --strip-unneeded libpigpiod_if.so
arm-linux-gnueabihf-size libpigpiod_if.so
text data bss dec hex filename
44380 5052 49248 98680 18178 libpigpiod_if.so
arm-linux-gnueabihf-gcc -I /usr/local/include -O3 -Wall -pthread -fpic -c -o pigpiod_if2.o pigpiod_if2.c
arm-linux-gnueabihf-gcc -shared -pthread -Wl,-soname,libpigpiod_if2.so.1 -o libpigpiod_if2.so.1 pigpiod_if2.o command.o
ln -fs libpigpiod_if2.so.1 libpigpiod_if2.so
arm-linux-gnueabihf-strip --strip-unneeded libpigpiod_if2.so
arm-linux-gnueabihf-size libpigpiod_if2.so
text data bss dec hex filename
55850 5052 1988 62890 f5aa libpigpiod_if2.so
gcc -O3 -Wall -pthread -c -o x_pigpio.o x_pigpio.c
gcc -o x_pigpio x_pigpio.o -L. -lpigpio -pthread -lrt
/usr/bin/ld: skipping incompatible ./libpigpio.so when searching for -lpigpio
/usr/bin/ld: cannot find -lpigpio
collect2: error: ld returned 1 exit status
make: *** [Makefile:60: x_pigpio] Error 1
Ultimately, I found it easier to use CMake to cross-compile pigpio, but that solution seems dependent on community support.