在Mac OS X中将错误与vrpn和libusb链接

时间:2015-01-30 05:21:30

标签: macos libusb vrpn

当我尝试在Mac上编译vrpn 7.33时,我收到以下错误。它说libusb是针对不同的架构而编译的,而不是vrpn正在编译:

Linking CXX executable client_and_server
ld: warning: ignoring file /usr/local/lib/libusb-1.0.dylib, file was built for i386 which is not the architecture being linked (x86_64): /usr/local/lib/libusb-1.0.dylib
Undefined symbols for architecture x86_64:
  "_libusb_claim_interface", referenced from:
      vrpn_Tracker_USB::vrpn_Tracker_USB(char const*, vrpn_Connection*, unsigned short, unsigned short, long) in libvrpnserver.a(vrpn_Tracker.C.o)
      vrpn_Tracker_USB::mainloop() in libvrpnserver.a(vrpn_Tracker.C.o)
  "_libusb_close", referenced from:
      vrpn_Tracker_USB::vrpn_Tracker_USB(char const*, vrpn_Connection*, unsigned short, unsigned short, long) in libvrpnserver.a(vrpn_Tracker.C.o)
      vrpn_Tracker_USB::~vrpn_Tracker_USB() in libvrpnserver.a(vrpn_Tracker.C.o)
      vrpn_Tracker_USB::mainloop() in libvrpnserver.a(vrpn_Tracker.C.o)
  "_libusb_exit", referenced from:
      vrpn_Tracker_USB::vrpn_Tracker_USB(char const*, vrpn_Connection*, unsigned short, unsigned short, long) in libvrpnserver.a(vrpn_Tracker.C.o)
      vrpn_Tracker_USB::~vrpn_Tracker_USB() in libvrpnserver.a(vrpn_Tracker.C.o)
  "_libusb_init", referenced from:
      vrpn_Tracker_USB::vrpn_Tracker_USB(char const*, vrpn_Connection*, unsigned short, unsigned short, long) in libvrpnserver.a(vrpn_Tracker.C.o)
  "_libusb_open_device_with_vid_pid", referenced from:
      vrpn_Tracker_USB::vrpn_Tracker_USB(char const*, vrpn_Connection*, unsigned short, unsigned short, long) in libvrpnserver.a(vrpn_Tracker.C.o)
      vrpn_Tracker_USB::mainloop() in libvrpnserver.a(vrpn_Tracker.C.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [server_src/client_and_server] Error 1
make[1]: *** [server_src/CMakeFiles/client_and_server.dir/all] Error 2
make: *** [all] Error 2

但是当我重新编译libusb将架构更改为x86_64时,我开始收到以下错误:

Linking CXX executable client_and_server
ld: warning: ignoring file /usr/local/lib/libusb-1.0.dylib, file was built for x86_64 which is not the architecture being linked (i386): /usr/local/lib/libusb-1.0.dylib
Undefined symbols for architecture i386:
  "_libusb_claim_interface", referenced from:
      vrpn_Tracker_USB::vrpn_Tracker_USB(char const*, vrpn_Connection*, unsigned short, unsigned short, long) in libvrpnserver.a(vrpn_Tracker.C.o)
      vrpn_Tracker_USB::mainloop() in libvrpnserver.a(vrpn_Tracker.C.o)
  "_libusb_close", referenced from:
      vrpn_Tracker_USB::vrpn_Tracker_USB(char const*, vrpn_Connection*, unsigned short, unsigned short, long) in libvrpnserver.a(vrpn_Tracker.C.o)
      vrpn_Tracker_USB::~vrpn_Tracker_USB() in libvrpnserver.a(vrpn_Tracker.C.o)
      vrpn_Tracker_USB::mainloop() in libvrpnserver.a(vrpn_Tracker.C.o)
  "_libusb_exit", referenced from:
      vrpn_Tracker_USB::vrpn_Tracker_USB(char const*, vrpn_Connection*, unsigned short, unsigned short, long) in libvrpnserver.a(vrpn_Tracker.C.o)
      vrpn_Tracker_USB::~vrpn_Tracker_USB() in libvrpnserver.a(vrpn_Tracker.C.o)
  "_libusb_init", referenced from:
      vrpn_Tracker_USB::vrpn_Tracker_USB(char const*, vrpn_Connection*, unsigned short, unsigned short, long) in libvrpnserver.a(vrpn_Tracker.C.o)
  "_libusb_open_device_with_vid_pid", referenced from:
      vrpn_Tracker_USB::vrpn_Tracker_USB(char const*, vrpn_Connection*, unsigned short, unsigned short, long) in libvrpnserver.a(vrpn_Tracker.C.o)
      vrpn_Tracker_USB::mainloop() in libvrpnserver.a(vrpn_Tracker.C.o)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [server_src/client_and_server] Error 1
make[1]: *** [server_src/CMakeFiles/client_and_server.dir/all] Error 2
make: *** [all] Error 2

注意链接器现在如何搜索原始i386架构。

为什么vrpn会在两种情况下都抱怨?

1 个答案:

答案 0 :(得分:0)

正在为多个体系结构同时编译

vrpn。这就是为单个架构编译libusb并不起作用的原因。

解决方案是使用以下命令序列同时为两个架构编译libusb

./configure
make CFLAGS="-arch x86_64 -arch i386" LDFLAGS="-arch x86_64 -arch i386"
sudo make install

如果您想了解有关在Mac OS X中编译通用二进制文件的更多信息,请查看以下链接: