2

I am trying to use make to build a binary from a source code for a program I need.

Link to source: https://github.com/pali/0xFFFF

It requires usb.h, which seems to be part of usblib-compat. I installed the latter by brew install usblib-compat. But still usb.h can't be seen, although I know where it is (under /usr/local/Cellar/usblib-compat/version/include).

I read a lot over the Internet and tried to set many environment variables, but no success. Any idea?

UPDATE

After many trials, I have 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:

CPPFLAGS += -I/usr/local/include
LDFLAGS += -L/usr/local/lib -Wl,-R/usr/local/lib

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.

In any case, I have still problems. Namely, the make'ing process outputs two warnings and an error, and then stops:

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") )

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.

2
  • In the man page for dlsym() (on macOS Sierra 10.12.3), it says: If dlsym() is called with the special handle RTLD_DEFAULT, then all mach-o images in the process (except those loaded with dlopen(xxx, RTLD_LOCAL)) are searched in the order they were loaded. This can be a costly search and should be avoided. So, you should be getting the symbol defined if you include <dlfcn.h>, unless you've managed to specify (directly or indirectly) a #define that prevents the symbol from being specified. Mar 8, 2017 at 7:42
  • @JonathanLeffler In usb-device.c I found the following: 21 #ifndef _GNU_SOURCE 22 #define _GNU_SOURCE 23 #endif 24 25 #include <stdio.h> 26 #include <stdlib.h> 27 #include <stdint.h> 28 #include <string.h> 29 #include <errno.h> 30 #include <ctype.h> 31 #include <signal.h> 32 #include <dlfcn.h> So dlfcn.h seems to be already included, and also _GNU_source is defined, which should enable the definition of RTLD_DEFAULT.
    – Enrico
    Mar 8, 2017 at 9:56

1 Answer 1

4

You haven't told which program you want to compile, so it is impossible to give specific advice.

The general advice is to look at the program's README's, documentation and/or Makefile for ways to specify the include path.

For example you might edit the Makefile directly to identify where the include path is specified. In many projects the program is compiled by gcc/llvm and the include paths are specified using "-I" arguments to the compiler.

You could find that spot in the Makefile and add:

  -I/usr/local/Cellar/usblib-compat/version/include
3
  • Link to the program: github.com/pali/0xFFFF. I have had a look at the Makefile but don't see where any compiler is invoked.
    – Enrico
    Mar 7, 2017 at 20:29
  • It is because the top-level Makefile does nothing but invoke the Makefile inside the src directory, where the compiler is invoked from. However, the project has a config.mk file in the top-level directory with an example of how to specify the include path. Just remove the # mark from the CPPFLAGS line, and change /usr/pkg/include to /usr/local/Cellar/usblib-compat/version/include.
    – jksoegaard
    Mar 8, 2017 at 21:00
  • Thank you, I realised it by myself... But anyway this was not enough. Many other tricks have been needed. But I have been successful! An extensive answer will be posted here in a few minutes.
    – Enrico
    Mar 8, 2017 at 21:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .