Должен ли я включить LibUSB в приложение MacOS и как мне указать, где искать? [дубликат]C++

Программы на C++. Форум разработчиков
Ответить
Гость
 Должен ли я включить LibUSB в приложение MacOS и как мне указать, где искать? [дубликат]

Сообщение Гость »


Я разрабатываю кроссплатформенное приложение, используя Avalonia на C#. Это зависит от написанной мной встроенной (C++) библиотеки, которая, в свою очередь, зависит от LibUSB. Приложение работает на моем компьютере, но когда я распространяю установщик (DMG) на другой компьютер, оно не может загрузить мой .dylib, поскольку не может найти dylib LibUSB. Обе библиотеки находятся в одном и том же месте, но ОС пытается загрузиться из /usr/local/lib и других стандартных мест. Похоже, это связано с тем, что dylib LibUSB «рекламирует» свое местоположение как /usr/local/lib, как это определено с помощью

Код: Выделить всё

otool -L
which then gets picked up by my native library. So, my questions are:
  • 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

    Код: Выделить всё

    --prefix
    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.
Note that the app seems to pick up my (native) dylib, but the "install_name" isn't set right in my dylib which causes LibUSB to not get found. (i.e. the problem is not in the .NET code)
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
shows

Код: Выделить всё

/opt/local/homebrew
or something similar (I have since removed the homebrew version). I built a release .tar.bz2 of LibUSB without specifying a prefix, after which

Код: Выделить всё

ottol -L
shows

Код: Выделить всё

/usr/local/lib
I ran

Код: Выделить всё

install_name_tool -id "@executable_path/libusb-1.0.0.dylib" libnative.dylib
where

Код: Выделить всё

libnative.dylib
is a pseudonym for my native library. I also tried various encarnations of

Код: Выделить всё

install_name_tool
but I haven't ruled it out as a solution since I was just trying random things and mostly with the first (homebrew) version of the library.
Update: 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:

    Код: Выделить всё

    ld: Undefined symbols: _CFBooleanGetTypeID, referenced from: _darwin_detach_kernal_driver in libusb-1.0.a[10](darwin_usb.o)
    and many other similar missing symbols. Maybe I need to reference other static libraries?
What I am expecting: When my native dylib is loaded it should look in the containing folder for libusb-1.0.0.dylib (or libusb-1.0.dylib)


Источник: https://stackoverflow.com/questions/781 ... re-to-look
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»