简体   繁体   中英

how to create libhidapi.dylib from source?

I have ongoing cross platform project (Win and Mac) where I need to access USB device. I have found HIDAPI library that perfectly fits all my requirements. Since there is no Delphi Firemonkey wrapper for HIDAPI library (at least I don't know for one) I am writing my own.

HIDAPI project web site http://www.signal11.us/oss/hidapi/ says: “On Windows, HIDAPI can optionally be built into a DLL.

This is true because I have successfully compiled source using visual studio and created DLL which works perfectly on Windows. 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?

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. Then you can use the links from Mac:

To compile as a Mac dynamic library (.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

Then the README itself tells you what prerequisites there are to build for mac, and how to generate the final shared object library:

 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

And how to generate the .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.

So you should be able to just follow those instructions but modify the .dylib extension and add the build flags: -dynamiclib and -fPIC

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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