MasterDevX / lampify

A simple CLI application to control the BLE lamp
29 stars 6 forks source link

Build fails undefined reference #2

Open littleboot opened 1 year ago

littleboot commented 1 year ago

Hello I'm trying to build 'lampify' but I'm unable to do so, I've tried building on Linux mint and Kali linux both fail the same way.

System info

Linux tom-mint 5.15.0-76-generic #83-Ubuntu SMP Thu Jun 15 19:16:32 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Install dependencies:

sudo apt install libbluetooth-dev libnotify-dev make gcc

Missing deps not listed in readme

git

Clone repo in downloads folder

cd ~/Downloads git clone https://github.com/MasterDevX/lampify.git cd lampify

Try building

make

Build fail 1

/usr/include/glib-2.0/glib/gtypes.h:32:10: fatal error: glibconfig.h: No such file or directory
   32 | #include <glibconfig.h>

Fix

Seems the missing header file is located at a different location in my system: /usr/lib/x86_64-linux-gnu/glib-2.0/include Fix: add the missing path to the Makefile

Build fail 2

gcc -Wall -Ofast -I /usr/include/glib-2.0 -I /usr/lib/glib-2.0/include -I /usr/include/gdk-pixbuf-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -lbluetooth -lnotify -o lampify lampify.c
/usr/bin/ld: /tmp/ccvBgzpw.o: in function `hciSetParams':
lampify.c:(.text+0x13d4): undefined reference to `hci_send_req'
/usr/bin/ld: /tmp/ccvBgzpw.o: in function `sendPacket':
lampify.c:(.text+0x1430): undefined reference to `hci_get_route'
/usr/bin/ld: lampify.c:(.text+0x143f): undefined reference to `hci_open_dev'
/usr/bin/ld: lampify.c:(.text+0x14c7): undefined reference to `hci_send_req'
/usr/bin/ld: lampify.c:(.text+0x14f3): undefined reference to `hci_send_cmd'
/usr/bin/ld: lampify.c:(.text+0x150c): undefined reference to `hci_le_set_advertise_enable'
/usr/bin/ld: lampify.c:(.text+0x152c): undefined reference to `hci_le_set_advertise_enable'
/usr/bin/ld: lampify.c:(.text+0x1537): undefined reference to `hci_close_dev'
/usr/bin/ld: /tmp/ccvBgzpw.o: in function `decodeCommand':
lampify.c:(.text+0x17e9): undefined reference to `notify_init'
/usr/bin/ld: lampify.c:(.text+0x17f5): undefined reference to `notify_notification_new'
/usr/bin/ld: lampify.c:(.text+0x1805): undefined reference to `notify_notification_set_timeout'
/usr/bin/ld: lampify.c:(.text+0x180f): undefined reference to `notify_notification_show'
collect2: error: ld returned 1 exit status
make: *** [Makefile:9: all] Error 1

I don't know how to fix this issue, it seems the hci functions are depreciated in Bluez, this might be causing the problem. I have no clue on how to fix this, I hope someone is able to help

Guenda85 commented 11 months ago

Same problem with me :-(

ophirHav commented 11 months ago

to fix build fail #2 change the Makefile for the compilation to be - $(CC) $(BASE).c $(CFLAG) $(INC) $(LIB) -o $(BASE)

littleboot commented 11 months ago

@ophirHav I will try this out tomorrow (actually I already gave up so many thanks for your reply). Can you elaborate a bit?

so changing line 9 of the makefile from: $(CC) $(CFLAG) $(INC) $(LIB) -o $(BASE) $(BASE).c

To: $(CC) $(BASE).c $(CFLAG) $(INC) $(LIB) -o $(BASE)

It seems you only changed the order of the parameters passed to gcc, does this mean original make file was always incorrect or did gcc change or something. How did you arrive at this fix if I may ask?

Update: It works now, I can compile the program without errors, thank you very much!

Guenda85 commented 11 months ago

worked for me as well :-)

yvesdm3000 commented 10 months ago

Newer versions of GCC have made the order of arguments relevant for linking and optimization purposes. That's why your sources should go first and then reference libraries the code uses.

t-chab commented 4 months ago

I had to replace line 3 of the Makefile to use pkg-config to build on Ubuntu 22.04 :

INC   = -I /usr/include/glib-2.0 -I /usr/lib/glib-2.0/include -I /usr/include/gdk-pixbuf-2.0

with

INC   = $(shell pkg-config --cflags glib-2.0) $(shell pkg-config --cflags gdk-pixbuf-2.0)
micahchoo commented 2 months ago

I had to replace line 3

For Ubuntu 24.04 also, this worked

mak448a commented 2 months ago

Yup, it built. Anyone else having the problem where it outputs [I] Connecting to the lamp [E] Failed to set advertising parameters!? I also tried running as root, but that didn't work. Also it doesn't make the light blink, and lights are unresponsive.