C: compile error

Need help with C, C++, perl, python, etc?

C: compile error

Postby kristof_v » 2007-04-19 19:35

HI, I grabbed this code from http://wiki.debian.org/MacBook#head-b64 ... 04704a07f1 to test the remote control of my macbook in Debian.

the code:
Code: Select all
/*BINFMTC:  -lusb -L /usr/X11R6/lib -lXt -lXtst

references:
http://www.madingley.org/macmini/kernel/ir.patch
http://www.gniibe.org/software/hub-ctrl.c

Copyright (c) 2006 Junichi Uekawa.

 */

#include <stdio.h>
#include <stdlib.h>
#include <usb.h>
#include <errno.h>
#include <X11/Xlib.h>
#include <X11/extensions/XTest.h>

#define USB_VENDOR_ID_APPLE   0x05ac
#define USB_DEVICE_ID_APPLE_IR  0x8240
#define USB_ENDPOINT  0x83

/*
MacBook

key pressed: 25 87 ee 44 2  menu
key pressed: 25 87 ee 44 4  >||
key pressed: 25 87 ee 44 7  >>
key pressed: 25 87 ee 44 8  <<
key pressed: 25 87 ee 44 b  +
key pressed: 25 87 ee 44 d  -
key pressed: 26 0 0 0 0  repeat
key pressed: 25 87 e0 44 6  ???

4th byte looks random.

 */

int keymap[8]={
  0,            /* reserved */
  97,            /* home */
  105,             /* next */
  105,            /* pgdn */
  99,             /* pgup */
  99,            /* pgup */
  105            /* pgdn */
};

void process_device(usb_dev_handle* uh)
{
  const int timeout=1000;   /* msec */
  const int size=32;
  char buf[size+1];
  int n;
  Display *display=XOpenDisplay(NULL);

  if(!display)
    {
      fprintf(stderr, "Cannot open display\n");
      return;
    }


  usb_detach_kernel_driver_np(uh,0);
 
  printf("claim: %p, %i\n", uh, (usb_claim_interface(uh,0)));
 
  while (1)
    {
      if((n=usb_interrupt_read(uh, USB_ENDPOINT, buf, size, timeout))>0)
   {
     int i;   
     printf("key pressed: ");
     for (i=0; i<n; ++i)
       printf("%x ", (int)(unsigned char)buf[i]);
     printf("\n");
     if ((buf[0]==(char)0x25)&&
         (buf[1]==(char)0x87)&&
         (buf[2]==(char)0xee))
       //(buf[3]==44) 4th byte is probably random.
       {
         printf("ack: \n");
         XTestFakeKeyEvent(display,
            keymap[buf[4]%16 >> 1],
            1,
            0);
         XSync(display, 0);
         sched_yield();
        
         XTestFakeKeyEvent(display,
            keymap[buf[4]%16 >> 1],
            0,
            0);
         XSync(display, 0);
         sched_yield();
       }
   }
      //printf("n=%i\n", n);
    }
  usb_close(uh);
}

int main(int ac, char** av)
{
  struct usb_bus* bus;
  struct usb_device* dev;
 
  usb_init ();
  usb_find_busses ();
  usb_find_devices ();

  for(bus=usb_get_busses(); bus; bus=bus->next)
    {
      for(dev=bus->devices; dev; dev=dev->next)
   {
     if((dev->descriptor.idVendor == USB_VENDOR_ID_APPLE) &&
        (dev->descriptor.idProduct == USB_DEVICE_ID_APPLE_IR))
       {
         printf("bus %s, dev %i\n",
           bus->dirname,
           dev->devnum);
         process_device(usb_open(dev));
       }
    
   }
    }
  return 0;
}


however when I try to compile it with gcc macbook-ir.c, it gives the following errors:

Code: Select all
gcc macbook-ir.c
macbook-ir.c:48: error: expected ‘)’ before ‘*’ token
macbook-ir.c: In function ‘main’:
macbook-ir.c:111: warning: assignment makes pointer from integer without a cast
macbook-ir.c:111: error: dereferencing pointer to incomplete type
macbook-ir.c:113: error: dereferencing pointer to incomplete type
macbook-ir.c:113: error: dereferencing pointer to incomplete type
macbook-ir.c:115: error: dereferencing pointer to incomplete type
macbook-ir.c:116: error: dereferencing pointer to incomplete type
macbook-ir.c:119: error: dereferencing pointer to incomplete type
macbook-ir.c:120: error: dereferencing pointer to incomplete type


any ideas???

grtz
kristof_v
 
Posts: 46
Joined: 2006-02-07 20:22

Postby brain » 2007-04-19 21:35

1. Install libusb-dev (apt-get install libusb-dev)
2. Add "#include <shed.h>" (without the quotation marks) in the top of the source file.
3. Compile with
Code: Select all
gcc `libusb-config --libs --cflags` -L /usr/X11R6/lib -lXt -lXtst -o macbook-ir macbook-ir.c
User avatar
brain
 
Posts: 253
Joined: 2006-04-25 17:15

Postby kristof_v » 2007-04-21 11:59

brain: shed.h was not found, so I gues you meant sched.h and used that?

I'm getting 1 error during compilation now:

macbook:/home/kristof# gcc `libusb-config --libs --cflags` -L /usr/X11R6/lib -lXt -lXtst -o macbook-ir macbook-ir.c
/usr/bin/ld: cannot find -lXt
collect2: ld returned 1 exit status

any idea??

grtz
kristof_v
 
Posts: 46
Joined: 2006-02-07 20:22

Postby kristof_v » 2007-04-21 12:17

fixed :)

I still had to install libxt-dev and lib-xtst-dev
kristof_v
 
Posts: 46
Joined: 2006-02-07 20:22


Return to Programming

Who is online

Users browsing this forum: No registered users and 3 guests

fashionable