qt 使用windows 的USB库 hid.dll 报错 :undefined reference to `HidD_GetAttributes(void*, _HIDD_ATTRIBUTES*)@8'等

 1、cmakeLists.txt 文件引入相应的库:

 

cmake_minimum_required(VERSION 3.5)

project(test1 LANGUAGES CXX)

file(GLOB SRC ./*.cpp ./*.h)
add_executable(test1 ${SRC})

include(GNUInstallDirs)

target_link_libraries(${PROJECT_NAME}
    hid
    setupapi
)
install(TARGETS test1
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

 

2、代码 以C的方式编译

 

#include "Standardcation.h"
extern "C" {
#include <setupapi.h>
#include <hidsdi.h>
#include <initguid.h>
}
#include <hidclass.h>

#include <Dbt.h>
#include <new>
#include <tchar.h>
#include <strsafe.h>
#include <iostream>
#include "CRC.h"
#include "RC4.h"

 

posted @ 2024-05-08 17:52  雾枫  阅读(34)  评论(0编辑  收藏  举报