简体   繁体   English

如何从源代码创建libhidapi.dylib?

[英]how to create libhidapi.dylib from source?

I have ongoing cross platform project (Win and Mac) where I need to access USB device. 我正在进行正在进行的跨平台项目(Win和Mac),需要访问USB设备。 I have found HIDAPI library that perfectly fits all my requirements. 我找到了完全符合我所有要求的HIDAPI库。 Since there is no Delphi Firemonkey wrapper for HIDAPI library (at least I don't know for one) I am writing my own. 由于没有用于HIDAPI库的Delphi Firemonkey包装器(至少我不知道),因此我正在编写自己的包装。

HIDAPI project web site http://www.signal11.us/oss/hidapi/ says: “On Windows, HIDAPI can optionally be built into a DLL. HIDAPI项目网站http://www.signal11.us/oss/hidapi/说:“在Windows上,可以选择将HIDAPI内置到DLL中。

This is true because I have successfully compiled source using visual studio and created DLL which works perfectly on Windows. 这是正确的,因为我已经使用Visual Studio成功编译了源代码并创建了在Windows上完美运行的DLL。 Now, since I am not C programmer and OSX is not my strongest skill I would like to know is it possible and how can I create libhidapi.dylib from given source code? 现在,由于我不是C程序员,并且OSX不是我的最强技能,所以我想知道是否有可能,如何从给定的源代码创建libhidapi.dylib?

Maybe I'm missing your question... but it looks like right at that link you provided there are instructions you need to compile as a .so for Linux/Mac platforms. 也许我错过了您的问题...但是,如果您有一些需要编译为.so说明,那么对于您在Linux / Mac平台上的链接来说,它似乎正确.so Then you can use the links from Mac: 然后,您可以使用Mac上的链接:

To compile as a Mac dynamic library (.dylib). 编译为Mac动态库(.dylib)。

Build Instructions 制作说明

... ...

Mac OS X: Change to the mac/ directory and run make. Mac OS X:转到mac /目录并运行make。

To build the Test GUI: 要构建测试GUI:

On Linux and Mac, run make from the hidtest/ directory. 在Linux和Mac上,从hidtest /目录运行make。 Make sure to first install fox-toolkit as >described in README.txt 确保首先按照README.txt中的说明安装fox-toolkit

Then the README itself tells you what prerequisites there are to build for mac, and how to generate the final shared object library: 然后,自述文件本身会告诉您要为mac构建哪些先决条件,以及如何生成最终的共享库:

 Prerequisites: --------------- 

Mac: 苹果电脑:

On Mac, you will need to install Fox-Toolkit if you wish to build the Test GUI. 在Mac上,如果要构建Test GUI,则需要安装Fox-Toolkit。 There are two ways to do this, and each has a slight complication. 有两种方法可以执行此操作,每种方法都有一点复杂性。 Which method you use depends on your use case. 使用哪种方法取决于您的用例。

If you wish to build the Test GUI just for your own testing on your own computer, then the easiest method is to install Fox-Toolkit using ports: sudo port install fox 如果您只想在自己的计算机上为自己的测试构建测试GUI,那么最简单的方法是使用端口安装Fox-Toolkit:sudo port install fox

If you wish to build the TestGUI app bundle to redistribute to others, you will need to install Fox-toolkit from source. 如果您希望构建TestGUI应用程序捆绑包以重新分发给其他人,则需要从源代码安装Fox-toolkit。 This is because the version of fox that gets installed using ports uses the ports X11 libraries which are not compatible with the Apple X11 libraries. 这是因为使用端口安装的fox版本使用的端口X11库与Apple X11库不兼容。 If you install Fox with ports and then try to distribute your built app bundle, it will simply fail to run on other systems. 如果您通过端口安装Fox,然后尝试分发已构建的应用程序捆绑包,它将无法在其他系统上运行。 To install Fox-Toolkit manually, download the source package from http://www.fox-toolkit.org , extract it, and run the following from within the extracted source: ./configure && make && make install 要手动安装Fox-Toolkit,请从http://www.fox-toolkit.org下载源软件包,解压缩并在解压缩的源中运行以下命令:./configure && make && make install

And how to generate the .so: 以及如何生成.so:

Building HIDAPI into a shared library on Unix Platforms: 将HIDAPI构建为Unix平台上的共享库:

On Unix-like systems such as Linux, FreeBSD, Mac, and even Windows, using Mingw or Cygwin, the easiest way to build a standard system-installed shared library is to use the GNU Autotools build system. 在使用Mingw或Cygwin的类似Unix的系统(例如Linux,FreeBSD,Mac甚至Windows)上,构建标准系统安装的共享库的最简单方法是使用GNU Autotools构建系统。 If you checked out the source from the git repository, run the following: 如果您从git存储库中签出了源代码,请运行以下命令:

./bootstrap ./configure make make install <----- as root, or using sudo ./bootstrap ./configure以root身份或使用sudo使make install <-----

If you downloaded a source package (ie: if you did not run git clone), you can skip the ./bootstrap step. 如果您下载了源软件包(即:如果您没有运行git clone),则可以跳过./bootstrap步骤。

./configure can take several arguments which control the build. ./configure可以采用几个控制构建的参数。 The two most likely to be used are: --enable-testgui Enable build of the Test GUI. 最可能使用的两个是:--enable-testgui启用测试GUI的构建。 This requires Fox toolkit to be installed. 这需要安装Fox工具箱。 Instructions for installing Fox-Toolkit on each platform are in the Prerequisites section above. 上面的“前提条件”部分提供了在每个平台上安装Fox-Toolkit的说明。

--prefix=/usr Specify where you want the output headers and libraries to be installed. --prefix = / usr指定要在何处安装输出头和库。 The example above will put the headers in /usr/include and the binaries in /usr/lib. 上面的示例将头文件放在/ usr / include中,将二进制文件放在/ usr / lib中。 The default is to install into /usr/local which is fine on most systems. 默认设置是安装到/ usr / local,在大多数系统上都可以。

So you should be able to just follow those instructions but modify the .dylib extension and add the build flags: -dynamiclib and -fPIC 因此,您应该能够仅遵循这些指示信息,但修改.dylib扩展名并添加构建标志: -dynamiclib-fPIC

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM