How do I make my gem place a .dll in a folder in the system PATH upon installation? - ruby

... and remove it upon un-installation, of course.
The issue is that other programs being called from my gem need to be able to find a certain file in the system PATH - setting the PATH programatically doesn't work, as these programs are being called in a way that they get a fresh environment.
I tried including these .dll files as "executables" in the gemspec, but that only seems to get some symlink type files in the {ruby}/bin folder, which causes errors because the programs in question are expecting the actual .dll.
As it is, I just have a note in the README asking people to manually copy the .dll files to a folder in the PATH, but it seems like there should be a better way to do this.
Any help would be appreciated - thanks!

I guess the dll is a native lib required by a java class?
If so, you can just put it somewhere in the lib folder and call java.lang.System.load to load it before the java class is used. It doesn't have to be in system PATH this way.

Related

If no additional directory in the install_name of a dynamic library, then which path does dyld search?

Mac, for a compiled project (using QT 5.5.0), I directly run the executable file, the error:
libraw.10.dylib not loaded;
OK, I know the reason.
One solution is to use install_name_tool to change the install name of libraw.10.dylib and put it in somewhere, like in the article:
"Qt for OS X - Deployment"
But right now I don't want to do this way.
One reason is that I do not need to really deploy it; so I want to make it simpler by only copying the library "libraw.10.dylib" to the right place.
The second reason is that I am curious what the default path for an install name without additional directory.
But no matter where I put the file "libraw.10.dylib", the same error comes out.
I tried to look into the details in the man page of dyld,
I couldn't figure it out.
Maybe all path variables are empty (I tried several popular variables, such as DYLD_FALLBACK_FRAMEWORK_PATH, DYLD_FALLBACK_LIBRARY_PATH, etc; they are empty).
Then I put the library "libraw.10.dylib" on the root, parallel to the folder "Applications". Still the same error.
So what dyld is looking for when it encounters:
libraw.10.dylib

Making folder containing executable into executable

I have a folder which contains an executable file (Exec.exe) and a lot of files that Exec.exe needs to run. Currently, it's pretty ugly having all of those files there when I only need to run the one executable. Is there any way to bundle them all into another executable that runs Exec.exe and also contains all of the files Exec.exe needs to run? Thanks for any help!
Yes, but I would recommend you only do it if you need to.
You can achieve this by adding your files as resources in your exe project, so they are added into the exe's binary at compile time. You can then access the files directly from your exe at runtime by using LoadResource and related functions. I'd recommend reading up on the Portable Executable (PE) file format if you're considering this route.
This is the way to do it if you, and again I stress, need to have only a single binary where you can still access your files. There are obvious downsides to doing this, such as it's much more coding to access the data as it's embedded in your application binary, and you can't easily update the files (check out resource hacker tool) without re-compiling your binary to include the new data.
If the only reason you want to do this is because it's "pretty ugly" seeing the additional files in the same directory as your exe, consider moving them into another directory, for example,
from:
MyExeDir
--myExe.exe
--myFile1.txt
--myFile2.dll
--myFile3.dat
to:
MyExeDir
--myExe.exe
--dat
----myFile1.txt
----myFile2.png
----myFile3.dat
or:
MyExeDir
--bin
----myExe.exe
--dat
----myFile1.txt
----myFile2.png
----myFile3.dat
So all the "ugly" looking files are out of the way.
Why don't you create a shortcut of "Exec.exe" and keep it somewhere handy ? If whats that you want ?
Or if you want to distribute your app, you can use Winrar/Winzip (winrar is the best) to create a compressed .exe of your entire folder, making "Exec.exe" as your startup app. Use the SFX option in winrar.

registration free COM without copying the dll to the same directory as the executable

How can I consume a registration free COM object without copying the dll to the same directory as the executable? Is this possible?
I would like a complete working sample or a detailed step-by-step guide for my exact scenario.
For example, I have the following components:
CppTestRunner.exe - vc++ console application
CppTests.dll - vc++ mfc dll
CsCOMServer.dll - c# COM visible dll
I do not want to modify the exe or its directory, like adding an external manifest.
CppTests.dll is in a different directory than the exe.
It is okay if CsCOMServer.dll is in the same directory as CppTests.dll.
CppTestRunner.exe calls LoadLibrary on CppTests.dll which works fine.
After embedding manifests and using the windows activation context apis, I was able to copy CsCOMServer.dll to the exe directory to verify that CppTests.dll can create an instance of CsCOMServer.dll without issues, but again, I am trying to avoid this step.
Currently, with CsCOMServer.dll in the same directory as CppTests.dll, and without CsCOMServer.dll in the exe directory, I am getting the following error when I call CoCreateInstance:
Error = 0x80070002 The system cannot find the file specified.
I have used sysinternals process monitor to track down the paths CppTestRunner.exe looks in, etc.
I notice that depending on the things I try to do, sometimes CppTestRunner.exe tries to read CsCOMServer.dll.config in the same directory as CppTests.dll, but no matter what I try to put in there, I was not able to get past the error.
Also depending on other things I try to do, CppTestRunner.exe tries to read CsCOMServer.dll in the same directory as CppTests.dll but for some reason, I still get the same error.
Anyone know of working code with this exact scenario?
As you can probably tell, this is part of some unit\integration tests.
As a simple workaround, I am currently copying CppTestRunner.exe to the same directory as CppTests.dll and running it from there, but would like to avoid this step.
Thank you.
.NET looks for managed registration-free COM first in the GAC, then in the executable's folder. It uses the activation context to read activation metadata, but not to determine the location of the files themselves.
You can save the DLL in a sub Folder, let say DLLFolder\YourDll.dll, and in the manifest file of yourDll, write the filename like
<file name = "DLLFolder\YourDll.dll">
But you need to keep the manifest file (of the DLL) in the location where the EXE is saved.

bin directory and PATH

I'm beginner in programming. Can somebody please explain (by simple words) what do I have inside the bin directory of program?
What is this PATH environment variable of windows, how does it work (please don't think that I don't know how to use Google, I just want to understand it more clearly)?
You usually put all the binary files for a program in the bin directory. This would be the executable itself and any dlls (dynamic link libraries) that the program uses.
This isn't essential as Windows use the PATH environment variable to look for dlls your program needs. This is a list of folders that Windows searches, in order, when it can't find a dll (say) in the current directory.
So if you want to have a dll used by more than one program you could put it in a location already on the PATH or add a new folder to the PATH.

Which Qt DLL's should I copy to make my program stand-alone?

I'm trying to make a distribution directory with my application. I've copied several Qt DLLs to that directory, and the program seems to be working, with one exception: it doesn't seem to find SQL plugin for SQLite. Copying qtsqlite.dll to the directory, doesn't allow my application to open or create SQLite files. What must be the direcotry structure or which additional files need to be copied so that the program can read the database?
you can use depends.exe to see exactly what the dependencies of your exe are and make sure they're all included.
Also, read this page about qt plugins. they are supposed to be in a specific directory called "plugins" and not in the main directory with all the other dlls.
Most probably, the qtsqlite.dll itself depends on original SQLite DLL's which you probably need to copy as well.
Don't forget to include an LGP license copy in your distribution as well as pointers to the original download ressources of the libs you include and their sources. To stay with the law :-)
Thanks to the link #shoosh provided, I was able to fix the problem. I needed to create sqldrivers subdirectory in the distribution dir with qsqlite.dll library inside. But that was just step one. Do you have any tips and resources on creating a full-blown Windows installer? I'm mainly a Linux programmer so this area is unknown to me.

Resources