Yubico / yubihsm-connector

https://developers.yubico.com/yubihsm-connector/
Apache License 2.0
30 stars 14 forks source link

gb build cannot find include files (and libraries) #2

Closed mouse07410 closed 5 years ago

mouse07410 commented 5 years ago

The current build process is unable to locate libusb.h:

$ ll /opt/local/include/libusb-1.0
total 40
drwxr-xr-x    3 root  admin     96 Aug 14 21:56 ./
drwxr-xr-x  591 root  admin  18912 Nov 26 10:45 ../
-rw-r--r--    1 root  wheel  72802 Mar 24  2018 libusb.h
$ make
/Users/ur20980/src/yubihsm-connector/vendor/src/github.com/thorduri/go-libusb/usb/config.go:17:11: fatal error: 'libusb-1.0/libusb.h' file not found
 #include <libusb-1.0/libusb.h>
          ^~~~~~~~~~~~~~~~~~~~~
1 error generated.
# github.com/thorduri/go-libusb/usb
FATAL: command "build" failed: exit status 2
make: *** [build] Error 1
$
klali commented 5 years ago

if libusb is installed with homebrew into default locations this just works, for other types of installs cgo probably has to be instructed about where to find include files and libraries for linking. I'm unsure how to do this, but it can probably be found out.

mouse07410 commented 5 years ago

AFAIK, Homebrew is less popular than, e.g., Macports, and has about 4600 ports, as opposed to 20000 ports provided by Macports. So, IMHO the choice of Home-brew as the default is arbitrary.

This is the solution that works for me:

diff --git a/Makefile b/Makefile
index befca5f..e10f9b5 100644
--- a/Makefile
+++ b/Makefile
@@ -7,8 +7,8 @@ MAKEFLAGS += --no-builtin-rules
 all: build

 build:
-       @gb generate ${GB_GEN_FLAGS}
-       @gb build ${GB_BUILD_FLAGS}
+       gb generate ${GB_GEN_FLAGS}
+       CGO_CFLAGS="-I/opt/local/include" CGO_LDFLAGS="-L/opt/local/lib" gb build ${GB_BUILD_FLAGS}

 rebuild: clean build