简体   繁体   English

如何在项目中使用CMake包含bluez最新版本库

[英]How to include bluez latest version library using CMake in project

I want to include bluez latest version (5.44) to my C program project. 我想在我的C程序项目中包含bluez最新版本(5.44)。 I am using CMake for build purpose. 我正在使用CMake进行构建。 I tried using pkg_check_modules as below 我尝试如下使用pkg_check_modules

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. 但是,它始终会找到较旧的版本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 . 我下载了最新的bluez版本,并使用sudo make install构建和sudo make install I am able to find and use the bluetoothctl tool. 我能够找到并使用bluetoothctl工具。

Firstly, you need to make sure that pkg-config can find your installed version of bluez . 首先,您需要确保pkg-config可以找到您安装的bluez版本。 If it can't, then CMake won't be able to either. 如果不能,那么CMake也将不能。

$ 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. 如果没有提供您期望的版本,则需要找到所需版本的bluez.pc ,并确保其目录位于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 . 由于您已声明使用sudo make install ,因此bluez.pc最有可能位于/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. 如果是这样,请执行使该更改永久存在于您的Shell上所需的操作。 Delete your CMake cache, and re-cmake your project. 删除您的CMake缓存,然后重新制作项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM