Click here to Skip to main content
15,614,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
These are original (C code ) instruction , do I link with libbluetooth or bluetooth or add libbluetooth-dev ? I am porting it to C++.

 To compile our program, invoke gcc and link against libbluetooth

# gcc -o simplescan simplescan.c -lbluetooth 

What I have tried:

add lbluetooth
add llibbluetooth

not sure I need to add "-l", I am not doing this directly to compiler options.
Updated 27-Dec-22 11:23am
Afzaal Ahmad Zeeshan 27-Dec-22 13:57pm    
You need to ask the code's author, as we do not have any context about the problem you are facing.

If this is an article on CodeProject, you can ask this question right below the article itself.

The -l compiler flag tells the compiler to search through a given library (either a shared (.so) or a ranlib library (.a) for otherwise undefined symbols. So for example if you wish to call sqrt you need to tell the C compiler to add the library with the object code for sqrt using -lm (N.B. g++ adds the math library automatically, so you don't have to, but gcc does not). So to link in functions defined in the bluetooth library, you need to add -lbluetooth to your compile command.

You will also need to add the libbluetooth-dev package to your system using apt install libbluetooth-dev

Your shell snippet above suggest you're working as root (shell prompt # ). This is generally frowned upon, and might be dangerous. Almost every experienced system administrator has at one time done something like 'rm -rf *' as root, with disastrous consequences. Use root only when you need to, and then you should get in the habit of using sudo to perform the system admin functions, like installing or updating packages.
Share this answer
CPallini 28-Dec-22 3:17am    

In qtCreator use option to link to "System Package" - libbluetooth-dev
not to the specific library.

Unfortunately QtCreator compile / link process cannot find the package,
but that is a different issue.
Share this answer
Using old C code which apparently have no idea about "blueZ " was "the problem".
Linking to "System Package" "bluez" is the solution.

The final question

if "libbluetooth-dev" is installed as a package, not as a library,
how does whatever development tool determine

it is "development package" , but it cannot be found ?

would "you dummy , you are trying to link to a package I don't give s..t about "

make more sense?

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900