title: Compiling a Linux program under Mac OS X
body: <p>I am trying to use <code>make</code> under Mac OS X (El Capitan) to compile a program which I know to work under Linux. The program makes use of USB libraries. I had to modify the config.mk file for these libraries to be found, but now I end up with errors in the compilation (undeclared identifiers).</p>
  
  <p>Link to source: <a href="https://github.com/pali/0xFFFF" rel="nofollow noreferrer">https://github.com/pali/0xFFFF</a></p>
  
  <p>It requires usb.h, which seems to be part of usblib-compat. I installed the latter by <code>brew install usblib-compat</code>. But still usb.h couldn't be seen, although I knew where it was: specifically, symbolic link to usb.h and to the library may be found under /usr/local/include and under /usr/local/lib, respectively.</p>
  
  <p>After many trials, I progressed somehow. Namely, the file config.mk is clearly read during the make'ing process, although I have to admit that it is not clear to me how this is done; anyway, I noticed two lines commented:</p>
  
  <pre><code>CPPFLAGS += -I/usr/local/include
  LDFLAGS += -L/usr/local/lib -Wl,-R/usr/local/lib
  </code></pre>
  
  <p>(for the sake of precision, in the original config.mk the local dir was replaced by a pkg dir. I replaced it in these lines.)</p>
  
  <p>I uncommented them and now something happens: the usb.h is found. I think the first of these variable definitions tells the compiler where to look tor header files, and the second tells the linker where to look for libraries - but again it is not completely clear to me.</p>
  
  <p>In any case, I have still problems. Namely, the make'ing process outputs two warnings and an error, and then stops:</p>
  
  <pre><code>usb-device.c:90:57: warning: unused parameter 'udev' [-Wunused-parameter]
  static void usb_reattach_kernel_driver(usb_dev_handle * udev, int interface) {
                                                          ^
  usb-device.c:90:67: warning: unused parameter 'interface' [-Wunused-parameter]
  static void usb_reattach_kernel_driver(usb_dev_handle * udev, int interface) {
  
  usb-device.c:324:13: error: use of undeclared identifier 'RTLD_DEFAULT' if ( dlsym(RTLD_DEFAULT, "libusb_init") )
  </code></pre>
  
  <p>Seems this program is difficult to port from Linux to Mac, although I think it should be portable. If anyone has any idea about what to do (apart from running a Linux distribution...), it would be much appreciated.</p>
  
  <p>EDIT</p>
  
  <p>dlfcn.h has the following:</p>
  
  <pre><code>#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
  #define RTLD_NOLOAD 0x10
  #define RTLD_NODELETE   0x80
  #define RTLD_FIRST  0x100   /* Mac OS X 10.5 and later */
  /*
   * Special handle arguments for dlsym().
  */
  #define RTLD_NEXT       ((void *) -1)   /* Search subsequent objects. */
  #define RTLD_DEFAULT    ((void *) -2)   /* Use default search algorithm. */
  #define RTLD_SELF       ((void *) -3)   /* Search this and subsequent objects (Mac OS X 10.5 and later) */
  #endif /* not POSIX */
  </code></pre>