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

Makefile change needed to link on Raspbian 11 #4

Open
mk2987 opened this issue Mar 21, 2022 · 1 comment
Open

Makefile change needed to link on Raspbian 11 #4

mk2987 opened this issue Mar 21, 2022 · 1 comment

Comments

@mk2987
Copy link

mk2987 commented Mar 21, 2022

While amouse builds fine on my x86 Linux machine (Arch Linux), it was failing at link time on my Raspberry Pi:

$ make
gcc -g -Wall -c src/include/serial.c -o src/include/serial.o
gcc -g -Wall -c src/../../shared/utils.c -o src/include/utils.o
gcc -g -Wall -c src/../../shared/mouse.c -o src/include/mouse.o
gcc -g -Wall -levdev -I/usr/include/libevdev-1.0/libevdev -I./include -o bin/amouse src/include/serial.c src/include/wrappers.c src/amouse.c ../shared/mouse.c ../shared/utils.c
/usr/bin/ld: /tmp/cclZh5iy.o: in function `open_usbinput':
/home/mkaushik/usb/amouse/linux/src/amouse.c:131: undefined reference to `libevdev_new_from_fd'
/usr/bin/ld: /home/mkaushik/usb/amouse/linux/src/amouse.c:136: undefined reference to `libevdev_has_event_type'
/usr/bin/ld: /home/mkaushik/usb/amouse/linux/src/amouse.c:137: undefined reference to `libevdev_has_event_code'
/usr/bin/ld: /home/mkaushik/usb/amouse/linux/src/amouse.c:138: undefined reference to `libevdev_has_event_code'
/usr/bin/ld: /home/mkaushik/usb/amouse/linux/src/amouse.c:139: undefined reference to `libevdev_has_event_code'
/usr/bin/ld: /home/mkaushik/usb/amouse/linux/src/amouse.c:140: undefined reference to `libevdev_has_event_code'
/usr/bin/ld: /home/mkaushik/usb/amouse/linux/src/amouse.c:141: undefined reference to `libevdev_has_event_code'
/usr/bin/ld: /home/mkaushik/usb/amouse/linux/src/amouse.c:142: undefined reference to `libevdev_free'
/usr/bin/ld: /tmp/cclZh5iy.o: in function `main':
/home/mkaushik/usb/amouse/linux/src/amouse.c:233: undefined reference to `libevdev_new_from_fd'
/usr/bin/ld: /home/mkaushik/usb/amouse/linux/src/amouse.c:324: undefined reference to `libevdev_next_event'
collect2: error: ld returned 1 exit status
make: *** [Makefile:30: amouse] Error 1

To fix this, we need to add the --no-as-needed flag to CFLAGS in the Makefile, or move -levdev to be after the object file names in the final build command. Apparently the linker on Raspbian 11 has --as-needed set by default (see the man page for ld for details on why this causes problems when -levdev is before the object files)

@Aviancer
Copy link
Owner

I had a look over this and while I can't easily directly test this at the moment, I've changed the order of parameters for the final linking so that the libraries are included last after the objects. That appears to be the most compatible way to handle this issue as "--no-as-needed" is not a fully standard flag from what I'm seeing.

This change is in the current cba115f commit of the dev branch.

Aviancer added a commit that referenced this issue Mar 31, 2022
… versions don't like defining variables inside switch blocks it turns out.
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