我已经在Mac OSX 10.9.5上编译了ZeroMQ,以便随后使用github.com/pebbe/zmq4链接到一个简单的Go程序,但是却遇到了我不理解或不知道该如何解决的错误。

# github.com/pebbe/zmq4
ld: warning: ignoring file /usr/local/lib/libzmq.dylib, file was built for x86_64 which is not the architecture being linked (i386): /usr/local/lib/libzmq.dylib
Undefined symbols for architecture i386:
  "_zmq_bind", referenced from:
      __cgo_59814aec404b_C2func_zmq_bind in zmq4.cgo2.o
      __cgo_59814aec404b_Cfunc_zmq_bind in zmq4.cgo2.o
     (maybe you meant: __cgo_59814aec404b_Cfunc_zmq_bind, __cgo_59814aec404b_C2func_zmq_bind )
  "_zmq_close", referenced from:
      __cgo_59814aec404b_C2func_zmq_close in zmq4.cgo2.o
      __cgo_59814aec404b_Cfunc_zmq_close in zmq4.cgo2.o
     (maybe you meant: __cgo_59814aec404b_C2func_zmq_close,
...
  "_zmq_z85_encode", referenced from:
      __cgo_59814aec404b_Cfunc_zmq_z85_encode in zmq4.cgo2.o
     (maybe you meant: __cgo_59814aec404b_Cfunc_zmq_z85_encode)
ld: symbol(s) not found for architecture i386
collect2: error: ld returned 1 exit status

我认为dylib是为x86_64(Mac)制作的,但为什么Go试图与i386链接呢?如何控制它并使其链接不同?甚至是正确的?

最佳答案

如果您自己构建libzmq,请使用--disable-shared --enable-static key 进行配置。如果您使用自制软件,请卸载zmq并手动构建该库。如果您需要“胖”通用静态库,请使用以下脚本:
https://github.com/drewcrawford/libzmq-ios

10-06 11:41