2010-07-10 179 views
0

当我试图编译程序本想出了:GCC编译错误

C:\Users\Mohit\Developer\C_Workspace\iPhoneInteraction\Debug>make all 
Building file: ../src/test.c 
Invoking: Cygwin C Compiler 
gcc -I"C:\cygwin\usr\include" -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"s 
rc/test.d" -MT"src/test.d" -o"src/test.o" "../src/test.c" 
cygwin warning: 
    MS-DOS style path detected: C:/cygwin/usr/include 
    Preferred POSIX equivalent is: /usr/include 
    CYGWIN environment variable option "nodosfilewarning" turns off this warning. 
    Consult the user's guide for more details about POSIX paths: 
    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames 
Finished building: ../src/test.c 

Building target: iPhoneInteraction.exe 
Invoking: Cygwin C Linker 
gcc -o"iPhoneInteraction.exe" ./src/test.o 
./src/test.o: In function print_device': 
/cygdrive/c/Users/Mohit/Developer/C_Workspace/iPhoneInteraction/Debug/../src/tes 
t.c:70: undefined reference to '_usb_open' 
/cygdrive/c/Users/Mohit/Developer/C_Workspace/iPhoneInteraction/Debug/../src/tes 
t.c:73: undefined reference to '_usb_get_string_simple' 
/cygdrive/c/Users/Mohit/Developer/C_Workspace/iPhoneInteraction/Debug/../src/tes 
t.c:84: undefined reference to '_usb_get_string_simple' 
/cygdrive/c/Users/Mohit/Developer/C_Workspace/iPhoneInteraction/Debug/../src/tes 
t.c:104: undefined reference to '_usb_get_string_simple' 
/cygdrive/c/Users/Mohit/Developer/C_Workspace/iPhoneInteraction/Debug/../src/tes 
t.c:112: undefined reference to '_usb_close' 
./src/test.o: In function 'main': 
/cygdrive/c/Users/Mohit/Developer/C_Workspace/iPhoneInteraction/Debug/../src/tes 
t.c:137: undefined reference to '_usb_init' 
/cygdrive/c/Users/Mohit/Developer/C_Workspace/iPhoneInteraction/Debug/../src/tes 
t.c:139: undefined reference to '_usb_find_busses' 
/cygdrive/c/Users/Mohit/Developer/C_Workspace/iPhoneInteraction/Debug/../src/tes 
t.c:140: undefined reference to '_usb_find_devices' 
/cygdrive/c/Users/Mohit/Developer/C_Workspace/iPhoneInteraction/Debug/../src/tes 
t.c:142: undefined reference to '_usb_get_busses' 
collect2: ld returned 1 exit status 
make: *** [iPhoneInteraction.exe] Error 1 

这里是我的代码,上面的方法错误是所有功能来自:

/* 
* testlibusb.c 
* 
* Test suite program 
*/ 

#include <stdio.h> 
#include <string.h> 
#include <usb.h> 

int verbose = 0; 

void print_endpoint(struct usb_endpoint_descriptor *endpoint) 
{ 
    printf("  bEndpointAddress: %02xh\n", endpoint->bEndpointAddress); 
    printf("  bmAttributes:  %02xh\n", endpoint->bmAttributes); 
    printf("  wMaxPacketSize: %d\n", endpoint->wMaxPacketSize); 
    printf("  bInterval:  %d\n", endpoint->bInterval); 
    printf("  bRefresh:   %d\n", endpoint->bRefresh); 
    printf("  bSynchAddress: %d\n", endpoint->bSynchAddress); 
} 

void print_altsetting(struct usb_interface_descriptor *interface) 
{ 
    int i; 

    printf(" bInterfaceNumber: %d\n", interface->bInterfaceNumber); 
    printf(" bAlternateSetting: %d\n", interface->bAlternateSetting); 
    printf(" bNumEndpoints:  %d\n", interface->bNumEndpoints); 
    printf(" bInterfaceClass: %d\n", interface->bInterfaceClass); 
    printf(" bInterfaceSubClass: %d\n", interface->bInterfaceSubClass); 
    printf(" bInterfaceProtocol: %d\n", interface->bInterfaceProtocol); 
    printf(" iInterface:   %d\n", interface->iInterface); 

    for (i = 0; i < interface->bNumEndpoints; i++) 
     print_endpoint(&interface->endpoint[i]); 
} 

void print_interface(struct usb_interface *interface) 
{ 
    int i; 

    for (i = 0; i < interface->num_altsetting; i++) 
     print_altsetting(&interface->altsetting[i]); 
} 

void print_configuration(struct usb_config_descriptor *config) 
{ 
    int i; 

    printf(" wTotalLength:   %d\n", config->wTotalLength); 
    printf(" bNumInterfaces:  %d\n", config->bNumInterfaces); 
    printf(" bConfigurationValue: %d\n", config->bConfigurationValue); 
    printf(" iConfiguration:  %d\n", config->iConfiguration); 
    printf(" bmAttributes:   %02xh\n", config->bmAttributes); 
    printf(" MaxPower:    %d\n", config->MaxPower); 

    for (i = 0; i < config->bNumInterfaces; i++) 
     print_interface(&config->interface[i]); 
} 

int print_device(struct usb_device *dev, int level) 
{ 
    usb_dev_handle *udev; 
    char description[256]; 
    char string[256]; 
    int ret, i; 

    udev = usb_open(dev); 
    if (udev) { 
     if (dev->descriptor.iManufacturer) { 
      ret = usb_get_string_simple(udev, dev->descriptor.iManufacturer, string, sizeof(string)); 
    if (ret > 0) 
     snprintf(description, sizeof(description), "%s - ", string); 
    else 
     snprintf(description, sizeof(description), "%04X - ", 
      dev->descriptor.idVendor); 
    } else 
     snprintf(description, sizeof(description), "%04X - ", 
      dev->descriptor.idVendor); 

    if (dev->descriptor.iProduct) { 
     ret = usb_get_string_simple(udev, dev->descriptor.iProduct, string, sizeof(string)); 
     if (ret > 0) 
     snprintf(description + strlen(description), sizeof(description) - 
      strlen(description), "%s", string); 
    else 
     snprintf(description + strlen(description), sizeof(description) - 
      strlen(description), "%04X", dev->descriptor.idProduct); 
    } else 
     snprintf(description + strlen(description), sizeof(description) - 
      strlen(description), "%04X", dev->descriptor.idProduct); 

} else 
    snprintf(description, sizeof(description), "%04X - %04X", 
     dev->descriptor.idVendor, dev->descriptor.idProduct); 

printf("%.*sDev #%d: %s\n", level * 2, "     ", dev->devnum, 
    description); 

if (udev && verbose) { 
if (dev->descriptor.iSerialNumber) { 
     ret = usb_get_string_simple(udev, dev->descriptor.iSerialNumber, string, sizeof(string)); 
     if (ret > 0) 
     printf("%.*s - Serial Number: %s\n", level * 2, 
      "     ", string); 
    } 
} 

if (udev) 
    usb_close(udev); 

if (verbose) { 
    if (!dev->config) { 
    printf(" Couldn't retrieve descriptors\n"); 
    return 0; 
    } 

    for (i = 0; i < dev->descriptor.bNumConfigurations; i++) 
    print_configuration(&dev->config[i]); 
} else { 
     for (i = 0; i < dev->num_children; i++) 
     print_device(dev->children[i], level + 1); 
    } 

    return 0; 
} 

int main(int argc, char *argv[]) 
{ 
    struct usb_bus *bus; 

    if (argc > 1 && !strcmp(argv[1], "-v")) 
    verbose = 1; 

    usb_init(); 

    usb_find_busses(); 
    usb_find_devices(); 

    for (bus = usb_busses; bus; bus = bus->next) { 
    if (bus->root_dev && !verbose) 
     print_device(bus->root_dev, 0); 
    else { 
     struct usb_device *dev; 

     for (dev = bus->devices; dev; dev = dev->next) 
     print_device(dev, 0); 
    } 
} 

return 0; 
} 

没有什么,我赶上我的代码是错的。有什么建议么?

回答

3

您需要在链接标志中包含-lusb以链接到libusb。如果需要的话,请记住包含它的库路径。

0

您可能没有链接到这些库库(.so.a.dylib) - 查看文档并查看您需要链接程序的库。

1

也许你错过了与库中的定义在他们的usb函数的链接。

因为您正在通过-I选项传递正确的路径,所以没有包含相关错误。 但是,您必须将其与-l<libname>链接,并使用-L<libpath>选项指定库的位置。