I built a library and I want to install the library to /usr/local/lib
using coreutils install
. The result of the build looks as follows:
libfoo.so -> libfoo.so.1
libfoo.so.1 -> libfoo.so.1.1
libfoo.so.1.1
I want to retain the symbolic links and install
the files as is to /usr/local/lib
. However, if I run
install libfoo* /usr/local/lib
the symbolic links are resolved and /usr/local/lib
looks as follows:
libfoo.so
libfoo.so.1
libfoo.so.1.1
In other words, these are all real files and no symbolic links.
The manpage of install
does not contain any information about resolving symbolic links. How can I install
symbolic links?
A symbolic link, also termed a soft link, is a special kind of file that points to another file, much like a shortcut in Windows or a Macintosh alias. Unlike a hard link, a symbolic link does not contain the data in the target file. It simply points to another entry somewhere in the file system.
Ln Command to Create Symbolic Links By default, the ln command creates a hard link. Use the -s option to create a soft (symbolic) link. The -f option will force the command to overwrite a file that already exists. Source is the file or directory being linked to.
Please be note that the install
utility always dereferences symlinks.
Please see my question here.
To copy files while preserving everything (symlinks, hard links, mode, etc) you can use cp -a
You can also use tar:
tar c -C source_dir file1 ... fileN | tar xv -C dest_dir
Be aware that both cp -a
and tar
will preserve user and group and that those files must probably be owned by root:root at the destination. You may have to add a chown afterwards.
I wondered about this too. After looking at the source code it would appear that install
is pretty aggressive about resolving links at install time. Here are some of the defaults it passes to cp
; the relevant ones don't get overridden later.
cp_option_init (struct cp_options *x)
{
cp_options_default (x);
x->copy_as_regular = true;
x->reflink_mode = REFLINK_NEVER;
x->dereference = DEREF_ALWAYS;
x->hard_link = false;
x->preserve_links = false;
x->preserve_mode = false;
x->symbolic_link = false;
(...)
The workaround would be to use cp
+ chmod
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With