Executive Summary / TL;DR
Run make uninstall
(or sudo make uninstall
, if you had to run sudo make install
) from the build directory where you ran make
and make install
. In builds configured with CMake, the build directory is usually not the top-level source directory. But besides that, uninstalling a program or library whose build was configured with CMake is no different from uninstalling other programs or libraries you have built from source code.
Some software supports make install
but not make uninstall
, in which case you may have to investigate what steps are taken when make install
is run, or consult the software's documentation to see if it specifies what files it puts where. However, PCL does appear to support uninstallation via make uninstall
.
Installation and Uninstallation with cmake
and make
CMake is a system for configuring a build. Once configured, the build must usually be carried out using some build system. On Unix-like operating systems such as Ubuntu, builds configured with CMake almost always use the Make build system.
Most software that uses CMake requires that you create a separate build directory, usually called build
, and run the cmake
command from that directory. The build directory is populated with files necessary to perform the build. Then you run make
in that directory. You should create the build
directory wherever the instructions for the software you're building advise to put it. Usually it will be a subdirectory of the source tree's top-level directory (the highest level directory created when you unpacked the source tarball or invoked a version control system like git
or bzr
to download the code).
When you run make
, it finds and reads a makefile -- usually called Makefile
-- that contains a list of targets, instructions for building the targets, and how the targets depend on one another. Usually the default target, which you do not have to specify, builds the software, and the install
target, which you do have to specify, installs it.
Many makefiles contain additional targets. The most common are:
- A
check
or test
target that tests the software that has been built. make check
or make test
may be run before make install
, and it is usually advisable to do so.
- An
uninstall
target that uninstalls the software by removing the files created by running make install
. (Occasionally make uninstall
has other behavior as well, to undo actions of make install
other than copying files, but usually it's just a matter of deleting files.) Not all software has an uninstall
target, but these days most does.
- A
clean
target to delete files from the source or build directory that were created during the build. Nearly all makefiles have this.
There are a few other relatively common targets like distclean
and realclean
that are less relevant to CMake. However, it's useful to know that if you're configured a build by running a configure script (./configure
) rather than CMake, then the configuration can usually be erased by running make distclean
.
A developer using CMake must write code to generate an uninstall
target -- CMake does not do this automatically. However, like many developers, the developers of PCL have done this and make uninstall
should work. See the next section ("A Step-By-Step Example") for details.
To uninstall software whose makefile supports an uninstall
target:
- The directory from which you ran
make install
(or sudo make install
) is the directory you must return to, to run make uninstall
(or sudo make uninstall
). For software that does not use CMake, this is usually the top-level directory of the source tree. But for software that does use CMake, it usually is not -- instead, it is usually a separate build directory.
- When installing software manually from source, it is best to keep the source code and all files created during the build, so you can uninstall the software easily. Therefore, once you have run
make install
, it's best not to run make clean
(nor to manually delete any files).
- However, if you did run
make clean
or delete the software's source code or build directory, it is still usually possible to uninstall successfully. Simply follow the same build steps, with the exact same version of the software, configured and built with the same options (or none if you didn't customize it), to get to the point where you can run make uninstall
(or sudo make uninstall
). For some software you may actually even have to run make install
again first, which will usually overwrite the files from the previous build. Then run make uninstall
(or sudo make uninstall
) as usual.
When there is no uninstall
target and you need to uninstall the software, you'll have to examine what files it creates. You can run make -n install
to show you what actions are taken by make install
. You do not need to run make -n install
with sudo
(assuming the initial make
didn't require sudo
). When make
is passed the -n
flag, it performs a dry run, which typically should not change anything, and therefore shouldn't need to do anything requiring elevated privileges.
A Step-By-Step Example: PCL 1.7.2
It's useful to give an example, and I might as well use the software you're actually trying to uninstall as that example. PCL 1.7.2 does appear to use cmake
to generate an uninstall
target in its makefile, and therefore should support make uninstall
.
In addition to examining uninstall_target.cmake.in
, I have verified that the generated Makefile
contains an uninstall
target on a 64-bit Ubuntu 16.04 test system. However, I haven't finished building PCL so I can install it and then test sudo make uninstall
. (My test machine is very slow, and PCL is big.) I plan to update this with additional information when I get the chance to do so, sometime after the build has finished.
When you installed PCL 1.7.2, you probably did something like this:
cd /usr/local/src
wget https://github.com/PointCloudLibrary/pcl/archive/pcl-1.7.2.tar.gz
tar xf pcl-1.7.2.tar.gz
cd pcl-pcl-1.7.2
mkdir build
cd build
cmake ..
make -j2
sudo make -j2 install
That is based (loosely) on the official instructions, but of course may not be exactly what you did. In particular, I downloaded and unpacked pcl-1.7.2.tar.gz
in /usr/local/src
. If you put it somewhere else then you'll have to replace /usr/local/src
with wherever you did put it.
Changing /usr/local/src
if necessary, you should be able to uninstall the software by running:
cd /usr/local/src/pcl-pcl-1.7.2/build
sudo make uninstall
Even if you ran make -j2 install
to allow multiple operations to take place simultaneously, there should be no need for you to pass the -j2
flag when you run make uninstall
.
apt-get
can't deal with it any more thangrep
can delete files. Another analogy would be like trying to play a PS4 game disk on your Xbox One. – sylphyk Jan 19 '17 at 22:11