halim
halim

Reputation: 386

Linking bluetooth library bluez in eclipse

I want to compile and run the following bluetooth scan code bluetooth scan code on eclipse neon.

I need to run it on Raspberry pi 3, so I did the following:

1- I downloaded the latest bluez version 5.43 from bluez

2- I compiled the downloaded file on my pi following the steps mentioned at Adafruit

3- I copied the compiled folder "bluez-5.43" from my Pi to the Pc to use it with eclipse. I am developing using Sysgcc cross compiling toolchain Cross Compiling on windows using SyssGcc toolchain

4- I prepared the eclipse after installing the SyssGcc toolchain using the steps on Setting Up Cross-Compilation In Eclipse

5- I created a c++ project and copied the main code of the bluetooth mentioned in the first URL and went to:

Project > Properties > C/C++ Build > Settings > GCC C++ Compiler > Includes

In Include paths (-l) i add: .....\bluez-5.43\lib\

On eclipse Project > Properties > C/C++ Build > Settings > GCC C++ Linker > Libraries

In libraries (-l) i add: bluetooth

In Library search path (-L) i add: ....bluez-5.43\lib.libs

but when I compile I get the following error, any help please for some one knows how to compile the code using eclipse and the cross compiling toolchain ??

    10:17:08 **** Incremental Build of configuration Debug for project Bluetooth_test ****
make all 
'Building target: Bluetooth_test'
'Invoking: Cross GCC Linker'
arm-linux-gnueabihf-gcc -L"C:\Users\aawad\Desktop\bluez-5.43\lib\.libs" -o "Bluetooth_test"  ./src/Bluetooth_test.o   -lbluetooth
c:/sysgcc/raspberry/bin/../lib/gcc/arm-linux-gnueabihf/4.9/../../../../arm-linux-gnueabihf/bin/ld.exe: cannot find -lbluetooth
collect2.exe: error: ld returned 1 exit status
make: *** [Bluetooth_test] Error 1

10:17:11 Build Finished (took 3s.57ms)

Upvotes: 0

Views: 1794

Answers (2)

dit
dit

Reputation: 21

the above did not suffice for me, to understand what I was missing I configured bluez with --disable-silent-rules (enables seeing compilation full commands) --enable-testing (so I can see a code similar to what I needed) then I run make VERBOSE=1 to see all needed linking: lib/libbluetooth-internal.la src/libshared-glib.la -lglib-2.0

Upvotes: 1

halim
halim

Reputation: 386

After several trials I was able to solve this error and the steps I mentioned above in the question are considered to be general preparation for some one wants to develop C using the Bluez Bluetooth protocol stack.

What worked out for me was:

Add the headers in the eclipse includes to make the CDT indexers know where the files are located

Project > Properties > C/C++ Build > Settings > GCC C++ Compiler > Includes

In Include paths (-l) i add: "C:\Users\aawad\Desktop\bluez-5.43\lib"

In the linking section:

On eclipse Project > Properties > C/C++ Build > Settings > GCC C++ Linker > Libraries

In libraries (-l) i add: bluetooth-internal

In Library search path (-L) i add: "C:\Users\aawad\Desktop\bluez-5.43\lib.libs"

compile and run the final executable on the Pi.. Turn your phone bluetooth and make it visible . You will find that the Pi can read your phone on the screen.

Upvotes: 0

Related Questions