Linking bluetooth library bluez in eclipse - c++

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)

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

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.

Related

Cross-compiling ALSA-lib for Raspberry PI on eclipse windows PC

I want to cross-compile alsa-lib for raspberry pi using eclipse on windows pc. I am using Sysgcc toolchain for windows used for cross-compiling on Raspberry PI.
I downloaded the alsa-lib library package from
"https://www.alsa-project.org/main/index.php/Download"
and copied it to my 'src' folder. I also added paths to this library as follows.
1) "Project-> Properties-> C/C++ Build-> Settings-> Cross GCC Compiler -> Includes"
and added the library path "C:\Users..\workspace\wavfileplay\src\alsa-lib-1.1.4.1"
2) "Project-> Properties-> C/C++ Build-> Settings-> Cross G++ Compiler -> Includes"
and added the library path "C:\Users..\workspace\wavfileplay\src\alsa-lib-1.1.4.1"
3) "Project-> Properties-> C/C++ Build-> Settings-> Cross G++ Linker -> Libraries"
and added "asound" in Libraries(-l) and gave the library search path for 'libasound.so' as "C:\Users..\workspace\wavfileplay\src".
But I am unable to compile the code. I removed several errors like not finding the header files by giving it the right path in different files. But now I am facing another error
expected ')' before '__SYMBOL_PREFIX' local.h
I didn't change the local.h file as it is part of the alsa-lib library. I alsa checked the brackets and they are fine.
First, is it possible to cross-compile alsa-lib for Raspberry PI on Windows using Eclipse?
If yes, then any ideas on how to remove this error?
Thanks alot

Faster way to link libraries in Eclipse CDT

I'm using Eclipse CDT Neon Release 4.6.2 on Ubuntu 16.04. I work with project where I need to include and link OpenCV 3.1 libraries. For each individual project, I always go to Window > Preferences > C/C++ Build > Settings and add the paths and names of the relevant OpenCV libraries under "Cross G++ Compiler > Includes" and "Cross G++ Linker > Libraries".
Is there a way to avoid doing this for every new project, e.g. through a configuration file for the required libraries which I can simply copy for every project? Entering the same information each time, especially the names of the libraries, is very time consuming.
You could use Makefile projects rather than Managed Build projects (in the New C++ Project dialog, select "Makefile project" as the project type instead of "Executable"/"Shared Library"/etc.).
You would then have to write a makefile that specifies what compiler commands to run to build the project, including the flags for OpenCV's include path and library path.
Once you write the makefile once, you can reuse most of it for different projects, either by copy-and-paste, or by factoring out the reusable bits into a shared makefile that you include from the projects' makefiles.
I switched to using Makefile projects exactly for this reason.

Compiler flags in Eclipse

My build requires that I issue the following commands:
$ g++ sniff.cpp -o sniff -lcrafter
However, in my Eclipse build, all the complier gets is:
g++ -o "sniffer_crafter" ./src/sniffer_crafter.o
After getting these commands it complains that I have an undefined reference to the library Crafter.
How can I resolve this linking issue using Eclipse? I have seen others answers to similar questions, but they don't seem to address Eclipse's current layout. I'm using the most recent edition of Eclipse Kepler.
Include libraries:-
right click on the project -->
Goto Properties
then goto --> C/C++ Build --> Settings
There you will find Linker and sub type Libraries.
Add the library path in Library Search Path on right hand side (where your .so file is located) and give the lib name in libraries
for libcrafter.so path --> /opt/myLib/lib
give path as /opt/myLib/lib
and library name as crafter

How to setup GTK+ to develop with Code::Blocks on Ubuntu Linux

I am trying to develop a GTK+ application on Ubuntu 11.4, using Code::Blocks.
www.gtk.org has instructions on building GTK+ from source, that looked complicated. But the Ubuntu package manager listed libgtk3-dev as a package that I installed.
Code::Blocks I installed using the Ubuntu Software Center.
Using the Code::Blocks project wizard to create a GTK+ project, when I build, the project fails to compile "cannot find gtk/gtk.h".
Clearly the GTK include (and lib) folders are not added to the Code::Blocks search folders. I have located the relevant paths and files...
Do I have to explicitly & manually add all the search paths to Code::Blocks' search paths? Or am I missing some installation step.
Assuming that you have located and installed the correct package. As of 2011, the current package was libgtk-3-dev then the pkg-config tool can be used to extract the linker and compiler flags - and with proper escaping in the Code:Blocks settings can inject the correct settings automatically.
Open Code::Blocks Settings > Compiler and Linker Settings... and add the following under Global Compiler Settings > Compiler Settings > Other Options
`pkg-config --cflags gtk+-3.0`
and add this to Global Compiler Settings > Linker Settings > Other Options
`pkg-config --libs gtk+-3.0`
With the ` this has the effect of running the pkg-config tool calling --cflags gtk+-3.0 (or --libs) which, assuming libgtk3-dev is installed, injects the necessary search folders and lib directives onto the gcc command line.
As an alternative, developer.ubuntu.com lists Anjuta as a C/C++ IDE that can create GTK+ projects. As an alternative to Code::Blocks its far more polished as an Ubuntu IDE.
Scratch that. Anjuta looses its sheen quickly.

How to setup a makefile in eclipse (C++)?

I have a project in Eclipse and I want to use my own makefile.
I went to
project -> properties -> C/C++ Build
and unchecked "Generate Makfiles Automatically". I have a makefile named Makefile in the project base dir which just contains:
all:
g++ *.cpp -o Simulator.exe
When I try to build, I get the following error:
Build of configuration MinGW GCC for project CacheOptimization
(Cannot run program "make": Launching failed)
How can I fix this and make eclipse compile my code?
You probably don't have MINGW configured properly, and Eclipse can't run "make". This might be useful: Setting up a compiler
Either:
install MSys package which includes make along with other useful tools (recommended),
or look into your project's settings under C/C++ Build and change the build command from make to mingw32-make, which is distributed as a part of MinGW.