Я разрабатываю кроссплатформенное приложение, используя Avalonia на C#. Это зависит от написанной мной встроенной (C++) библиотеки, которая, в свою очередь, зависит от LibUSB. Приложение работает на моем компьютере, но когда я распространяю установщик (DMG) на другой компьютер, оно не может загрузить мой .dylib, поскольку не может найти dylib LibUSB. Обе библиотеки находятся в одном и том же месте, но ОС пытается загрузиться из /usr/local/lib и других стандартных мест. Похоже, это связано с тем, что dylib LibUSB «рекламирует» свое местоположение как /usr/local/lib, как это определено с помощью
Код: Выделить всё
otool -L- Everywhere I look people assume the client machine will install libusb-1.0.0 themselves (usually via homebrew) is it bad to distribute the library myself? I want installation to be a one-click process and I don't expect the client to necessarily have LibUSB installed.
- If it is OK to distribute the library, how can I tell the OS to look in the current location? I think it has to do with either setting the when building LibUSB (or manually setting -install_name but I'm not sure where to do that in the Makefile), or using install_name_tool to set the folder, but just using "." doesn't seem to work in either case.
Код: Выделить всё
--prefix
I would also be fine with statically linking libUSB into my dylib (both will be licensed LGPL anyway) but I don't know how to do that either. This this answer suggests that as an option but doesn't explain how to do it.
What I have tried: Originally I installed LibUSB via homebrew and found that
Код: Выделить всё
otool -LКод: Выделить всё
/opt/local/homebrewКод: Выделить всё
ottol -LКод: Выделить всё
/usr/local/libКод: Выделить всё
install_name_tool -id "@executable_path/libusb-1.0.0.dylib" libnative.dylibКод: Выделить всё
libnative.dylibКод: Выделить всё
install_name_toolUpdate: I've now tried statically linking:
- I passed "enable-static" to the configure program and rebuilt libUSB, then did make and make install
- I copied libusb-1.0.a to my native library folder and ran my make, the build command is as follows:
A. `g++ -dynamiclib -std=c++20 -exported_symbols_list export_list libnative.cpp libusb-1.0.a -o libnative.dylib - I get the error: and many other similar missing symbols. Maybe I need to reference other static libraries?
Код: Выделить всё
ld: Undefined symbols: _CFBooleanGetTypeID, referenced from: _darwin_detach_kernal_driver in libusb-1.0.a[10](darwin_usb.o)
Источник: https://stackoverflow.com/questions/781 ... re-to-look
Мобильная версия