mosquitto-go-auth: undefined reference to `mosquitto_client_id'

I’m trying to install it on raspberry pi, but i get this:

pi@raspberrypi:~/go/src/mosquitto-go-auth $ make
go build -buildmode=c-archive go-auth.go
go build -buildmode=c-shared -o go-auth.so
# github.com/iegomez/mosquitto-go-auth
/usr/bin/ld: $WORK/b001/_x003.o: in function `mosquitto_auth_acl_check':
auth-plugin.c:(.text+0x3ec): undefined reference to `mosquitto_client_id'
/usr/bin/ld: auth-plugin.c:(.text+0x3f8): undefined reference to `mosquitto_client_username'
collect2: error: ld returned 1 exit status
make: *** [Makefile:3: all] Error 2

can you help me out of this, thank you

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 34 (22 by maintainers)

Commits related to this issue

Most upvoted comments

@mkohns Thanks!!!
My host env is ubuntu 18.04, go 1.15.3 ,mosquitto 1.6.12 and go auth 1.1. I successfully build linux/arm target when I modify export CGO_LDFLAGS="-shared -Wl,-unresolved-symbols=ignore-all"
I modify “go build -x -buildmode=c-shared -o go-auth.so”, I saw that cgo attach “-pie” to link parameters which cause this warning when target env is linux/arm.

Hi, I stumbled across this issue and debugged a bit. I still do not know the root cause for mosquitto-go-auth no building on raspberry pi - but i found a dirty solution for building this setup for rpi4

ENV MOSQUITTO_VERSION=1.6.10 ENV GO_VERSION=1.13.8

The reported linker error from @arctic-alpaca can actually be ignored. The reference is present - no idea why cgo has trouble finding it. With this patch file saved to patch.go-auth.go.rpi4 in docker subdirectoy

2a3
> // #cgo linux armhf LDFLAGS: -Wl,-unresolved-symbols=ignore-all

and this change in Dockerfile

#Copy the patch for rpi
COPY patch.go-auth.go.rpi4 .

#Get / build the plugin.
RUN mkdir mosquitto-go-auth && \
    cd mosquitto-go-auth && \
    git clone https://github.com/iegomez/mosquitto-go-auth.git . && \
    export PATH=$PATH:/usr/local/go/bin && \
    export CGO_CFLAGS="-I/usr/local/include -fPIC" && \
    export CGO_LDFLAGS="-shared" && \
    patch go-auth.go ../patch.go-auth.go.rpi4 && \
    make

The docker image can be build and runs smoothly with the newest version of mosquitto and auth plugin.

I suppose the patch file can be merged into master as the cgo directive should only hit armhf. But please double check.

@arctic-alpaca Thanks for sharing that description, it’ll surely be useful for anyone following your approach!

On the plugin version issue, I just created this PR which I believe fixes it: https://github.com/iegomez/mosquitto-go-auth/pull/103 Nevertheless, I’m waiting on comments in https://github.com/iegomez/mosquitto-go-auth/issues/96 to see if there’s anything else that needs consideration.

Cheers!

Hi! As the readme states, when building for Mosquitto 1.5 or later, you need to export some flags before:

export CGO_CFLAGS="-I/usr/local/include -fPIC"
export CGO_LDFLAGS="-shared"
make

Let me know if that works.