TheThingsArchive / packet_forwarder

Packet forwarder for Linux based gateways
MIT License
84 stars 92 forks source link

wrapper doesn't link libmpsse #83

Closed jeremyherbert closed 6 years ago

jeremyherbert commented 7 years ago

When building the packet forwarder, I get the following errors:

# github.com/TheThingsNetwork/packet_forwarder/wrapper
wrapper/../lora_gateway/libloragw/libloragw.a(loragw_spi.o): In function `lgw_spi_open':
loragw_spi.ftdi.c:(.text+0x38): undefined reference to `OpenIndex'
loragw_spi.ftdi.c:(.text+0x5a): undefined reference to `PinLow'
loragw_spi.ftdi.c:(.text+0x6a): undefined reference to `PinHigh'
wrapper/../lora_gateway/libloragw/libloragw.a(loragw_spi.o): In function `lgw_spi_close':
loragw_spi.ftdi.c:(.text+0xaa): undefined reference to `Close'
wrapper/../lora_gateway/libloragw/libloragw.a(loragw_spi.o): In function `lgw_spi_w':
loragw_spi.ftdi.c:(.text+0xfa): undefined reference to `Start'
loragw_spi.ftdi.c:(.text+0x10a): undefined reference to `FastWrite'
loragw_spi.ftdi.c:(.text+0x117): undefined reference to `Stop'
wrapper/../lora_gateway/libloragw/libloragw.a(loragw_spi.o): In function `lgw_spi_r':
loragw_spi.ftdi.c:(.text+0x1b8): undefined reference to `Start'
loragw_spi.ftdi.c:(.text+0x1c8): undefined reference to `Transfer'
loragw_spi.ftdi.c:(.text+0x1d3): undefined reference to `Stop'
wrapper/../lora_gateway/libloragw/libloragw.a(loragw_spi.o): In function `lgw_spi_wb':
loragw_spi.ftdi.c:(.text+0x2fe): undefined reference to `Start'
loragw_spi.ftdi.c:(.text+0x397): undefined reference to `FastWrite'
loragw_spi.ftdi.c:(.text+0x3a8): undefined reference to `Stop'
wrapper/../lora_gateway/libloragw/libloragw.a(loragw_spi.o): In function `lgw_spi_rb':
loragw_spi.ftdi.c:(.text+0x599): undefined reference to `Start'
loragw_spi.ftdi.c:(.text+0x5ad): undefined reference to `FastWrite'
loragw_spi.ftdi.c:(.text+0x5d9): undefined reference to `FastRead'
loragw_spi.ftdi.c:(.text+0x5e8): undefined reference to `Stop'
collect2: error: ld returned 1 exit status

Looking closer at the files in the wrapper directory, it seems that the cgo flags are not set to link libmpsse. One cannot use CGO_LDFLAGS because the order of linker arguments matters, and that appends it onto the end of the existing args. The correct line in the various wrapper/*.go files should be:

// #cgo LDFLAGS: -lm -lmpsse ${SRCDIR}/../lora_gateway/libloragw/libloragw.a

Yes, I realise this breaks other the non-ftdi builds. Still trying to work out how to solve that.

Environment

jeremyherbert commented 7 years ago

Given that a specific version of libmpsse is required, is there a reason that libmpsse isn't just included in this repository ? It could be bundled into libloragw fairly easily. I can provide a pull request for this.

egourlao commented 7 years ago

Thanks for your feedback! We're trying to keep the repository clean, so we'd like to avoid storing libmpsse in it. However, it would probably be a good idea to specify more explicitly in the docs which version of lmpsse to download, and how to install it.

jeremyherbert commented 7 years ago

I actually think that the docs for how to do it are pretty good. The problem for me here is that some linker flags are missing in the go wrapper.

egourlao commented 7 years ago

I'd rather not add those linker flags in the Go files, since libmpsse is only required for FTDI builds - for which we plan to drop support mid-term. It'd also mean every developer would have to install libmpsse to develop, even for SPI gateways... Another solution could be to move all the cgo flags in the Makefile. What do you think?

jeremyherbert commented 7 years ago

That sounds like a much better idea!

jeremyherbert commented 7 years ago

Do you have any plans to support a USB-based setup then?