首页 > 解决方案 > Mbient Lab Sensor API C++ 帮助:Visual Studio 2019 的未声明标识符?

问题描述

我最近购买了一个 Mbient Lab IMU 蓝牙传感器,我正在尝试按照此处找到的教程使用 API。

我在 Visual Studio 2019 中使用 CMAKE 构建了项目。我创建了一个解决方案文件,我正在努力开始为项目编写代码。我创建了一个解决方案,包括在 src 文件夹中找到的目录,链接包含 Win32 库的文件夹,并将其添加到链接器输入部分的附加依赖项中。但是,在遵循代码第一部分中看到的简单教程时,我收到 write_gatt_char、read_gatt_char 和 enable_char_notify 函数是未声明的标识符的错误,我找不到修复程序。

一个主要区别是 connection.h 文件不存在。相反,具有这些功能的文件位于单独文件夹中的 btle_connection.h 头文件中。

代码如下所示:

#include "metawear/core/metawearboard.h"
#include "metawear/platform/btle_connection.h"


int main(int argc, char** argv) 
{
    MblMwBtleConnection btle_conn = {nullptr, write_gatt_char, read_gatt_char, enable_char_notify};
    MblMwMetaWearBoard* board = mbl_mw_metawearboard_create(&btle_conn);
}

我收到一个 C2065 错误,这些函数是未声明的标识符。

此外,在 btle_connectoin 头文件中,这些函数定义在如下结构中:

/**
 * Wrapper class containing functions for communicating with the MetaWear through a Bluetooth Low Energy connection.
 */
typedef struct {
    /**
     * Provides the calling function the ability to pass any context specific data required
     */
    void *context;
    /** 
     * Writes the characteristic and value to the device
     * @param context           Pointer to the <code>context</code> field
     * @param caller            Object using this function pointer
     * @param characteristic    Gatt characteristic to write
     * @param value             Value to write as a byte array
     * @param length            Length of the byte array
     */
    void (*write_gatt_char)(void *context, const void* caller, MblMwGattCharWriteType writeType, const MblMwGattChar* characteristic, 
            const uint8_t* value, uint8_t length);
    /**
     * Reads the value of the characteristic from the device
     * @param context               Pointer to the <code>context</code> field
     * @param caller                Object using this function pointer
     * @param characteristic        Gatt characteristic to read
     * @param handler               Callback function to handle the received value
     */
    void (*read_gatt_char)(void *context, const void* caller, const MblMwGattChar* characteristic, MblMwFnIntVoidPtrArray handler);
    /**
     * Enables notifications for characeristic changes
     * @param context               Pointer to the <code>context</code> field
     * @param caller                Object using this function pointer
     * @param characteristic        Characteristic to enable notifications for
     * @param handler               Callback function for handling characteristic notifications
     * @param ready                 Callback function to handle when the enable notify task is completed
     */
    void (*enable_notifications)(void *context, const void* caller, const MblMwGattChar* characteristic, MblMwFnIntVoidPtrArray handler, MblMwFnVoidVoidPtrInt ready);
    /**
     * Register a handler for disconnect events
     * @param context               Pointer to the <code>context</code> field
     * @param caller                Object using this function pointer
     * @param handler               Handler to respond to the disconnect event
     */
    void (*on_disconnect)(void *context, const void* caller, MblMwFnVoidVoidPtrInt handler);
} MblMwBtleConnection;

任何帮助将不胜感激!我是否有可能错误地链接/构建它?

标签: c++buildlinkersensors

解决方案


尽管函数是在btle_connection头文件中声明的,但正如您所指出的,它们没有被定义。我们必须在调用之前编写这些函数的定义/实现mbl_mw_metawearboard_create

简单的文档


推荐阅读