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

标签 c macos firemonkey dylib hidapi

我正在进行跨平台项目(Win 和 Mac),我需要访问 USB 设备。我找到了完全符合我所有要求的 HIDAPI 库。由于没有用于 HIDAPI 库的 Delphi Firemonkey 包装器(至少我不知道),所以我正在编写自己的包装器。

HIDAPI 项目网站 http://www.signal11.us/oss/hidapi/说: “在 Windows 上,可以选择将 HIDAPI 内置到 DLL 中。 “

这是真的,因为我已经使用 visual studio 成功编译了源代码并创建了在 Windows 上完美运行的 DLL。现在,因为我不是 C 程序员而且 OSX 不是我最强的技能我想知道是否有可能以及如何从给定的源代码创建 libhidapi.dylib?

最佳答案

也许我遗漏了您的问题...但看起来就在您提供的链接中,您需要为 Linux/Mac 平台编译为 .so 的说明。然后您可以使用来自 Mac 的链接:

编译为 Mac 动态库 (.dylib)。

Build Instructions

...

Mac OS X: Change to the mac/ directory and run make.

To build the Test GUI:

On Linux and Mac, run make from the hidtest/ directory. Make sure to first install fox-toolkit as >described in README.txt

然后 README 本身告诉你构建 mac 有哪些先决条件,以及如何生成最终的共享对象库:

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

Mac:

On Mac, you will need to install Fox-Toolkit if you wish to build the Test GUI. 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

If you wish to build the TestGUI app bundle to redistribute to others, you will need to install Fox-toolkit from source. 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. If you install Fox with ports and then try to distribute your built app bundle, it will simply fail to run on other systems. 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

以及如何生成.so:

Building HIDAPI into a shared library on Unix Platforms:

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. If you checked out the source from the git repository, run the following:

./bootstrap ./configure make make install <----- as root, or using sudo

If you downloaded a source package (ie: if you did not run git clone), you can skip the ./bootstrap step.

./configure can take several arguments which control the build. The two most likely to be used are: --enable-testgui Enable build of the Test GUI. This requires Fox toolkit to be installed. Instructions for installing Fox-Toolkit on each platform are in the Prerequisites section above.

--prefix=/usr Specify where you want the output headers and libraries to be installed. The example above will put the headers in /usr/include and the binaries in /usr/lib. The default is to install into /usr/local which is fine on most systems.

因此您应该能够按照这些说明进行操作,但修改 .dylib 扩展名并添加构建标志:-dynamiclib-fPIC

关于c - 如何从源代码创建 libhidapi.dylib?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15359169/

相关文章:

检查 C 预处理器中的串联定义

c - 注册虚拟机和加载/存储架构?

macos - 在当前窗口/ View Controller 的不同窗口/ View Controller 中执行代码

swift - 如何使用 AppleScript shell 在标准错误输出中获取数据

delphi - 在 Delphi 中检测互联网访问

将负十进制数转换为二进制数

c - strtok 以字符串文字作为参数

python - 如何将 python 2.6 设置为 Mac OS X Lion 中的默认设置?

delphi - 如何操纵 TPath 中的各个点?

delphi - Delphi XE2中的Dcu