Linking native hidapi and libusb-1.0 library in eclipse on Ubuntu - linux

I am new to Ubuntu and searched on-line for two days, tried a lot of solutions but do not have any luck yet. If anyone can help with this, I will appreciate.
I wrote a program in Java with eclipse on Windows. My program makes use of Java hidapi library, which is a Java wrapper of the C version hidapi library (.dll). In eclipse, by adding the Java hidapi to the build path and setting the C hidapi as a native library, everything works just fine.
Now I want to do the same on Ubuntu. The same Java hidapi is used, which now will make use of the C version hidapi library for Linux (a .so file). When making the C version hidapi library for Linux, it turns out that I need another library called libusb-1.0 (which hidapi needs to deals with the low level communication). So I install libusb-1.0 (now I have a libusb-1.0.so file under /usr/lib/i386-linux-gnu), make the C version hidapi library for Linux. I have a small C program and I test it under bash, it works so I believe until this point everything, both libsub-1.0.so and C version hidapi library for Linux libhidapi-jni.so are installed/generated correctly, and when running the small C program the system is able to find the shared libusb-1.0.so library without explicitly mentioning where libsub-1.0 is (which makes sense because libusb-1.0 is installed in a place where the system loader will always search).
So I go to eclipse. I import the eclipse work space, add the Java hidapi to the build path (as I did in Windows), move the C version hidapi library for Linux (the .so file) into a folder called 'lib' (where the .dll version of native library also resides). And I set the native library to 'lib', by "build path" -> "configure build path" -> "libraries" tab -> "native library location". So till this point, the two native libraries are: libusb-1.0 under /usr/lib/i386-linux-gnu, and hidapi.so under 'wherever eclipse workspace is'/lib. Finally in the source code I add two lines:
System.loadLibrary("usb-1.0"); // Call this line A.
System.loadLibrary("hidapi-jni"); // Call this line B.
I run the program as a Java application. It reports "java.lang.UnsatisfiedLinkError: no usb-1.0 in java.library.path" at line A. So I guess the Java runtime is not able to find where libsub-1.0 is.
Just for clarification, I already did the following trials, none of them worked.
Remain the two libraries where they are, add vm argument (Run -> Run Configuration -> Arguments -> VM arguments): -Djava.library.path="${workspace_loc:project_name}/lib;
/usr/lib/i386-linux-gnu". It gives: "java.lang.UnsatisfiedLinkError: no usb-1.0 in java.library.path" at line A.
Undo 1. Move libsub-1.0.so to 'wherever eclipse workspace is'/lib, so now the two .so files are together. Set .jar's native library location to this folder. It gives "java.lang.UnsatisfiedLinkError: blablabla: undefined symbol: libusb_control_transfer" at line B. So I think it founds the libusb library, however the symbol (which should be in libusb) is still unresolved. This is really weird.
Can anyone help me? Thanks in advance.

Related

How to discover the Paths to Loading Binaries

I have a problem where I need to know the filesystem path of the current binary, as well as those of any loading (as opposed to loaded) binaries. Here is an example (for Windows): Say we have an executable A.exe, which dynamically binds to B.dll, which in turn binds to C.dll. How could code executing in C.dll get the file paths of C.dll, B.dll, and A.exe?
Oh, and I need to be able to do it on Linux, Mac, and Windows.
On Linux, the closest thing I've found is dl_iterate_phdr, but the who-loaded-who info is missing.
On Windows, The Dynamic-Link functions don't have quite the right functionality.
On Mac, all I can find is what's in dlfcn.h, which is rather pithy for this purpose.
Thanks.

Read Linux or Windows MEX file on Mac OS [duplicate]

I've been given a Matlab program that uses an external C function. I only have the compiled version of this external function, and the extension is .mexglx . From what I have already red, it seems that this extension is the mex-file version compiled with linux. I run matlab under windows XP, and my problem is that my Matlab is not able to read the .mexglx extension. So my question is: is there any mean to change a file with the .mexglx extension to a .mex? Because for the moment I do not have the source code in C, so I can't recompile it correctly. I precise that my version of Matlab is R2007b if it can help.
Thank you for your answer
No there is no way, sorry. You need to get the source code to build it for a different platform.

Manifest for my own (native) DLL

NOTE: This question is not about MFC/CRT DLL linking with/without .manifest file, avoiding manifest-lookup (i.e. force load from current path), VC redist installation and similar issues.
I have set of DLLs, which is used by different applications. These applications and the DLL have some product version (like 7.0, 8.0 etc). To summarize, let me use one DLL, and two applications.
App.exe depends on Core.DLL
GoodApp.exe also depends on Core.DLL
App.EXE of version 7.0 would need Core.DLL of version 7.0. Similary, GoodApp of version X, would need DLL of version X.
Since DLL is to be shared by different applications, I have put the DLL into some common path. This avoids DLL to be pasted on all paths. Some \SharedDLL path is setup for this. And (assume), I have set up PATH variable for this.
So, when any of application would load, OS will simply load the Core.DLL from this common path.
All fine. But what if App.exe is 64-bit/Debug, or other configuration? The common-DLL path cannot have all DLLs (32/64, Debug/Release). On the similar lines, App.exe of version Y, cannot use Core.DLL of version X (It is not that X>Y, or Y>X, but just that X!=Y, and App of X version cannot use DLL of version Y).
In short, App-32bit-Release-VersionX, would need exactly DLL-32bit-Release-VersionX, and nothing else! Since DLL name is same, I cannot put them into one common path. And since, there are dozens of applications (and DLLs too!) that depends on Core.DLL, I just don't want to waste space and time for copying the DLL into EXE's path.
Yes, I use post-build-setup to copy the DLL into all paths, appropriately. This solves time, but waste space. And if new application comes in, PBS must be modified to copy to that new path also.
Question is: How to utilizie the .manifest feature, used by Windows/MFC/CRT DLLs? They do utilize WinSxS folder for such thing.
Maybe this will help you:
How to: Embed a Manifest Inside a C/C++ Application,
Manifest Generation in Visual Studio
Working with Visual Studios C++ manifest files
Also follow the links in those pages

Compiling Libpng in Windows 7 or getting a hold of Libpng12.dll (and understanding how to link .DLL in VS)

I've been using Libpng15 in Windows 7, but I've been getting errors in relation to the
Unresolved External _png_set_longjmp_fn error when I compile my code. I followed the directions in the aforementioned link, and while it DID compile without any errors, I wound up with a message saying that I needed libpng12.dll to continue.
So, I did some Googling for libpng12.dll...nothing came up but generic "find x.dll" websites which appeared to be scams.
I've tried reading the INSTALL docs for the libpng source code on their website, and all that I see is instructions on how to do it via Unix based systems. I tried to do this in Cygwin with no luck, so I'm kind of stuck on how to compile this library.
All in all, I'm willing to do either the compilation or just using the .dll, though the problem is that I can't find a working .dll for version 12.
Another thing I tried was downloading binaries from here, which claimed to be "libpng12 for windows". I then copied the files into my VC compiler directory, which overrode libpng15, I think. Still, when I link against it statically and run my program in VC, it says that I require the .DLL file. The libpng12.dll file was in fact a .dll.a file instead. I honestly am not sure to link these (I tried linking it statically by typing "libpng12.dll.a" in the Linker Input setting through VS).
If I can go the .dll route for libpng12, how do I do this? Where is the file? How do I link it in VS?
Any help would be appreciated, as it seems there really isn't a whole lot of information on this. Either that, or I'm just not looking properly.
Look in the "projects" directory of the libpng distribution, and use one of the visual projects.
As mentioned above Look in the "projects" directory of the libpng distribution
Then make the adjustments outlined here
https://stackoverflow.com/a/38547948/293792
Which I note here for simplicities sake
(as stated there) adding two lib values to
Config -> Linker -> Input -> Additional Dependencies
these values are ucrt.lib;vcruntime.lib
Ensuring the build type is /MD
Allowed me to build these older versions, and fix that error on Windows 10 VS2015.
This link seems to have an installer for 1.2 for you:
http://gnuwin32.sourceforge.net/packages/libpng.htm
it's 32 bit. Not sure if that makes a difference for you.

(How) does a cmake configuration differ conceptually from a Visual-C++ project file?

To get from C++ sourcecode to a binary module, the process is roughly as follows:
set_of_source_files[a.cpp, b.cpp, ...] // conceptually, it doesn't matter where these are
||
|| Compiler <- [compiler_settings]
\/
set_of_object_files
||
|| Linker <- [linker_settings]
\/
binary module (dynamic library or executable)
Now, I know Visual Studio projects, they
Define a set of source files (directory structure and layout basically doesn't matter / is defined inside the project file)
Define the compiler settings for all (optionally each) of the source files
Define the linker settings
Define where to put generated output files
I don't know cmake, but apparently(?), the info one configures with cmake differs slightly from the info one puts into vc[x]proj files.
Is a "cmake configuration" just a differently formatted "vcproj file" or is there a conceptual difference? (Except for the obvious one (I assume) that the info I put into a cmake configuration is platform independent.)
An alternative twist to this question would be to answer -- in the context of above -- why/if(?) one would switch to cmake when only compiling for Windows with Visual-C++.
Cmake is a cross-platform make -- it starts from a set of source files and a relatively abstract set of directions about what to do with them. Based on those, it generates a set of platform-specific files. If you specify Windows/Visual Studio as the target, it can/will generate a vx[x]proj file for you to use.
Even if you're only using Visual C++ on Windows, it's possible you could benefit from cmake. The obvious possibility would be if you want to target a number of different versions of Visual Studio, and be able to directly generate the correct files for each, instead of generating files for the oldest version you want to support, and then depend on Visual Studio's upgrade feature to convert those to the target version.
Based on my experience with VS's upgrade capability (not particularly great), I'd say that could/would be a reasonable and valid use.

Resources