2015-02-04 10 views
1

또한 테스트 - 벽과 -std = C99 및 C11 (물론 작동하지 않음)libusb를 -1.0 libusb_get_device_list() 실패

$ gcc -o usb -L/usr/local/lib -lusb-1.0 -I/usr/local/include usbtest.c 

출력 :

usbtest.c: In function ‘main’: 
usbtest.c:14:1: error: label ‘brd_ftdi’ used but not defined 
libusb_get_device_list(context, &&brd_ftdi); 

usbtest.c :

#include <stdio.h> 
#include <libusb-1.0/libusb.h> 
int main() { 
    libusb_device* brd_ftdi; 
    libusb_device_handle** brd_ftdi_handle; 
    libusb_context* context; 

    //libusb_device *** list = &&brd_ftdi; 

    //libusb_init (libusb_context **); 
    libusb_init (&context); 

    libusb_get_device_list(context, &&brd_ftdi); 
    //libusb_open(brd_ftdi, brd_ftdi_handle); 

    //libusb_exit(struct libusb_context *); 
    libusb_exit(context); 

    return 0; 
} 

정의되지 않습니까? 나도 알아,하지만 libusb_get_device_list() (거기에 목록을 넣어) 할 예정이다, 그래서 WTF? 또한 brd_ftdi에 대한 포인터를 선언하고 그 결과를 대신 전달하는 테스트를 수행했습니다.

답변

1

오류 메시지를 자세히 읽으면 레이블brd_ftdi이 정의되어 있지 않으며 변수가 아닙니다.

&&brd_ftdi을 작성했기 때문에 &&the address of a label이라는 GCC 확장 프로그램입니다. 표준이 아닙니다.

변수의 주소는 &입니다. 변수의 주소는 &brd_ftdi입니다.

libusb_get_device_list 함수는 에 대한 포인터 목록의 주소를 쓸 주소 인 libusb_device***을 사용합니다. 이처럼 사용할 수 있습니다

libusb_device **list_of_devices; 
libusb_get_device_list(context, &list_of_devices); 

list_of_devices은 (libusb_device들에 대한 포인터의) 목록의 첫 번째 포인터에 대한 포인터입니다.

libusb_device_handle에 대한 포인터에 초기화되지 않은 포인터를 전달하기 때문에 현재 코멘트가있는 libusb_open에 대한 호출에 문제가 있습니다. 이 함수는 사용자가 지정한 주소에 결과 (libusb_device_handle *)를 씁니다.