Reputation: 1829
I want to include bluez latest version (5.44) to my C program project. I am using CMake for build purpose. I tried using pkg_check_modules
as below
pkg_check_modules (BLUEZ REQUIRED bluez)
include_directories(${BLUEZ_INCLUDE_DIRS})
link_directories(${BLUEZ_LIBRARY_DIRS})
But It always finds the older version 5.37. How can I point this to take latest version ?
I already tried this as well but it throws the error as below.
pkg_check_modules (BLUEZ REQUIRED bluez=5.44)
include_directories(${BLUEZ_INCLUDE_DIRS})
link_directories(${BLUEZ_LIBRARY_DIRS})
Error getting :
Checking for module 'bluez=5.44'
--
CMake Error at /usr/share/cmake-3.5/Modules/FindPkgConfig.cmake:367 (message):
A required package was not found
Call Stack (most recent call first):
/usr/share/cmake-3.5/Modules/FindPkgConfig.cmake:532 (_pkg_check_modules_internal)
CMakeLists.txt:30 (pkg_check_modules)
I downloaded the latest bluez version and built and installed using sudo make install
. I am able to find and use the bluetoothctl
tool.
Upvotes: 1
Views: 2264
Reputation: 1
For installing:
sudo apt-get install libbluetooth-dev
Check installing:
execute@execute:~$ pkg-config --cflags --libs bluez
-lbluetooth
My cmake:
pkg_check_modules (BLUEZ REQUIRED bluez)
add_executable(test_linux_bluetooth test_linux_bluetooth.cpp)
target_link_libraries(test_linux_bluetooth PRIVATE bluetooth)
Upvotes: 0
Reputation: 1004
While the question has a manually compiled Bluez
version included in many cases people might run into the exact same issue after doing a standard installation of Bluez
through apt
on any Debian system.
However to do development in a project with Bluez one also has to install Bluez developement files. This can be done with
apt install libbluetooth-dev
which should in turn install the bluez.pc file in the standard location making both pkg-config --modversion bluez
and any pkg_check_modules (BLUEZ REQUIRED bluez)
resolve correctly.
Upvotes: 0
Reputation: 2747
Firstly, you need to make sure that pkg-config
can find your installed version of bluez
. If it can't, then CMake won't be able to either.
$ pkg-config --modversion bluez
If that does not give you the version you expect, then you need to find the bluez.pc
for the version that you want, and make sure its directory is at the beginning of PKG_CONFIG_PATH. Since you stated that you used sudo make install
, the bluez.pc
you want is most likely at /usr/local/lib/pkgconfig/bluez.pc
. (You will need to look yourself to be sure.) If that's the case, then
$ PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:${PKG_CONFIG_PATH} pkg-config --modversion bluez
should return the the version your looking for. If so, do what's necessary to make that change permanent to your shell. Delete your CMake cache, and re-cmake your project.
Upvotes: 0