Is it possible to add a library path to an init script? - shared-libraries

We have an application that runs as a service daemon on a RedHat system.
For now, the RPM we have to install this package creates a soft link from our application's library folder into /usr/lib64, and the daemon recognises that.
I would like to be able to set the LD_LIBRARY_PATH in the init script (/etc/init.d/myscript) so that we don't need to create that soft link (therefore, if multiple applications that use different versions of the library are installed, they will use what is in their own installation folder, and also we won't mess with the standard lib folders).
Is this possible? I tried a simple LD_LIBRARY_PATH=/opt/myapp/lib:/$LD_LIBRARY_PATH but that did not seem to work...

Try next in your init script:
LD_LIBRARY_PATH=/opt/myapp/lib:/$LD_LIBRARY_PATH
export LD_LIBRARY_PATH

Related

Is it possible to distribute and use .so files without having to install?

I have a .Net Core application which is to run on Ubuntu. With it I'm looking to distribute 2 .so files that the application depends upon. The app would load those libraries via a [DllImport("mylibrary")] attribute.
If I try to run my application as-is, it complains that it cannot find mylibrary. This is because the library doesn't exist in the search path. If I install the libraries via apt-get instead of distributing them, everything works (the libraries end up in /usr/lib/x86_64-linux-gnu/ which is part of my search path for libraries).
This isn't a very scalable solution. I want something that just "works" when running dotnet myapplication.dll without having to pre-install via apt-get (or otherwise) my .so files.
How can I get the library loader to work with my local .so files without requiring some extra step by the end user before running my application?
The idea of having the .Net Core application running some installation / bash commands upon startup to setup the environment sounded like a decent idea except it requires sudo. This isn't a deal-killer, but isn't terribly clean either.
Any ideas?

Installing Node in a linux grid server

So some background, I'm installing Node on a host server, but it's a grid server not a server that's solely for my website.
The grid server doesn't have a root user/ administrative powers. So to install node I found this workaround: http://iantearle.com/blog/media-temple-grid-and-nodejs . It's a Linux Grid server, I've never used Linux so if someone could explain to me what the commands mean, especially: ./configure --prefix=~/opt/
Lastly I followed the steps but when I try to run the node command in the server it says node:command not found - which is why I'm trying to understand the steps. Thanks
To explain the process:
Configure
The configure script is responsible for getting ready to build the software on your specific system. It makes sure all of the dependencies for the rest of the build and install process are available, and finds out whatever it needs to know to use those dependencies.
Unix programs are often written in C, so we’ll usually need a C compiler to build them. In these cases the configure script will establish that your system does indeed have a C compiler, and find out what it’s called and where to find it.
Make
Once configure has done its job, we can invoke make to build the software. This runs a series of tasks defined in a Makefile to build the finished program from its source code.
The tarball you download usually doesn’t include a finished Makefile. Instead it comes with a template called Makefile.in and the configure script produces a customised Makefile specific to your system.
3.Make Install
Now that the software is built and ready to run, the files can be copied to their final destinations. The make install command will copy the built program, and its libraries and documentation, to the correct locations.
--prefix=~/opt/ -> will set the build directory to /home/yourhome/opt directory.
Now if you didnt get errors while doing those 3 steps explained above make sure you did the following:
nano ~/.bash_profile
export PATH=~/opt/bin:${PATH}
nano is a text editor and you are opening .bash_profile file with it.
you need to add export PATH=~/opt/bin:${PATH} in that file and save it using ctrl+x
Then restart your terminal.
Specified github repository for nodejs is outdated. use the following link instead.
git clone https://github.com/nodejs/node.git
P.S node:command not found usually happens when the program is not installed correctly or it's executable isnt in your terminal's PATH variable.

Can I avoid exporting LD_LIBRARY_PATH by hardcoding library paths in the executable?

I'm zipping a pre-built (no source/object files) binary application for distribution. The binary application requires a couple of libraries not included by default. The only way I seem to be able to get the application to start on the end-user is by including a run.sh that sets the library path to the current directory:
export LD_LIBRARY_PATH=./:$LD_LIBRARY_PATH
./MyApp.out
However, I'd really like to allow the user to just unzip the zip and doubleclick MyApp.out (without the shell script). Can I edit MyApp.out to search the current directory for the library? I've done something similar on OSX using install_name_tool, but that tool isn't available here.
You want to set the rpath. See this answer. So link using
gcc yourobjects*.o -L/some/lib/dir/ -lsome -Wl,-rpath,.
But you might want even to use -Wl,-rpath,$PWD or perhaps -Wl,-rpath,'$ORIGIN'. See this.
You could also (and this should work for a pre-built executable) configure your /etc/ld.so.conf by adding a line there with an absolute path (of the directory containing the lib), then running ldconfig -v ... See ldconfig(8)
I would suggest adding /usr/local/lib into /etc/ld.so.conf and making a symlink from /usr/local/lib/libfoo.so to e.g. $HOME/libfoo.so etc... (then run ldconfig ...). I don't think adding a user specific directory to /etc/ld.so.conf is reasonable ...
PS. What you really want is to package your application (e.g. as a *.deb package for Debian or Ubuntu, or an *.rpm for Fedora or Redhat). Package management systems handle dependencies!

install library in home directory

In Linux(Ubuntu) I am trying to run a tool and it is showing error "library missing". I don't have permission to install anything in the system (or simply sudo is not possible from my user account).Is it possible to install missing library (libstdc++.so.6 in my case) in my home directory (without sudo) and change the environment-variables etc. so that all other tools/programs can find it?
Yes, assuming the library is in /home/user/lib. You can set use the LD_LIBRARY_PATH environment variable to find the lib. LD_LIBRARY_PATH=/home/user/lib, which will find the library. If you have to compile it yourself you will want to use configure --prefix=/home/user.
I'm surprised that libstdc++.so.6 isn't available on the system already. Take a look in /usr/lib/x86_64-linux-gnu. If could just be your program isn't multiarch aware.

How to use CMake to update library path?

I am writing a shared library for GNU/Linux, which will install for now with "sudo make install". I have CMake recipes to create the files and install them in '/usr/local/lib/app', and the libraries and links are created correctly.
But the library path is not updated and I must run "sudo ldconfig /usr/local/lib/app' manually to make the library available.
Several other packages on my system put their libraries in a specific folder under /usr/local/lib, so I am assuming that's proper.
How then to have CMake update the library path for the system as well as create the files and install them? What is the proper way to do this?
I'd also like it accomplished so that the library path update survives a system restart.
Thanks,
bcw
I'd also like it accomplished so that the library path update survives a system restart.
I'm not aware of any CMake-specific facility. However, you should be able to add rules such as the following in order to make the change persistent.
echo "/usr/local/bret/lib" > /etc/ld.so.conf.d/bret-i386.conf
echo "/usr/local/bret/lib64" > /etc/ld.so.conf.d/bret-x86_64.conf
/sbin/ldconfig
You'll still need to re-run the ldconfig when you overwrite files in bret/lib{,64}.

Resources