describing how to build dynamically linked (lib)primecount without root
Playing with cmake a bit, I found how to set up libprimecount and primecount without root, something that's valuable in a number of settings, e.g. on HPC clusters, other shared machines - or building libprimecount extensions (e.g. Python ones). Should this be added to docs?
The following is only tested on Linux so far.
- set the desired location, e.g.
export WDIR=$HOME/tmp - install libprimesieve as follows:
cd primesieve
cmake -DBUILD_STATIC_LIBS=OFF -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=$WDIR .
make -j install # no sudo!
- install primecount as follows
cd primecount
cmake -DBUILD_STATIC_LIBS=OFF -DBUILD_SHARED_LIBS=ON \
-DCMAKE_INSTALL_PREFIX=$WDIR \
-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE -DCMAKE_INSTALL_RPATH=$WDIR \
-DCMAKE_SKIP_BUILD_RPATH=FALSE -DBUILD_LIBPRIMESIEVE=OFF \
-DCMAKE_FIND_ROOT_PATH=$WDIR/lib/cmake \
-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY .
make -j install # no sudo!
- done, now you can do
$WDIR/bin/primecount 1000000and it will work as it should.
this works on macOS too.
Should this be added to docs?
Personally I feel like the documentation should not contain too many expert topics. My documentation is currently written so that beginners and intermediate devs can get started quickly. Expert devs that are e.g. packaging software (or writing bindings) usually know exactly what build settings to use in their particular environment. Even if this piece of information is missing in the documentation experts will likely be able to figure it out quickly by themselves.
I personally spent many hours figuring this out, and I have been packaging software for 20+ years. cmake docs don't provide ready to use instructions of this sort, and their docs are lacking in general (e.g. try to find info on ldconfig there) - aimed at the users with root access, often, and totally avoiding the situation I describe here.
There are no instructions of this sort found on stackoverflow, I looked hard there. Let's ask a cmake expert, whether this is easy to figure out ? @isuruf ?
beginners and intermediate devs can get started quickly
No, if you are a primecount beginner wanting to run it without a root access, e.g. a student with access to a shared Unix server, your current docs are not helping, they always have sudo in them.
Or assuming one only has an office Linux desktop, centrally managed, thus, no root (that's the case where I work, for instance).
I'm not sure I understand what the issue is.
@isuruf - the question is whether it is well-documented elsewhere how to correctly install dynamic libs and executables built with cmake if the user does not have root.
I propose to add such details to the docs here, as it appears tricky. IMHO the standard cmake docs assume that on Linux one installs into /usr/local, using sudo.