How do you fix `cmake .. && make install` "No rule to make target install"?
I consulted the Cmake textbook I have (or if you go to [the cmake
tutorial0(https://cmake.org/cmake-tutorial/)). According to the textbook, in addition to setting the cmake
variable CMAKE_INSTALL_PREFIX
you also need to invoke the cmake
function install()
for anything you wish to be installed via the generated Makefile
.
So in my case I set the variable in my CMakeLists.txt via:
set(CMAKE_INSTALL_PREFIX path/to/directory)
then under each add_library()
and add_executable()
I added:
install(TARGETS name1
DESTINATION ${CMAKE_INSTALL_PREFIX}
)
Then when I did cmake .. && make && make install
I was successful and the expected files were installed at the expected destination.
Related videos on Youtube
Comments
-
Trevor Boyd Smith almost 2 years
I was trying to use
cmake
to install some libraries and executables that are built viacmake
.I found What is cmake equivalent of 'configure --prefix=DIR && make all install '? which seemed to be easy. It looked like you just need to set the
cmake
variableCMAKE_INSTALL_PREFIX
and thenmake install
should work.I found that setting the
cmake
variable alone did not fixmake install
and I kept getting the error message "No rule to make target install".How do you fix
cmake .. && make install
"No rule to make target install"?p.s.
cmake
version is 2.8.x-
Jesper Juhl almost 6 yearsAre you sure "install" is a valid target defined by that project?
-
Trevor Boyd Smith almost 6 years@JesperJuhl see my answer
-
-
super almost 6 yearsThis is not really a generic solution. Might have worked in your case, but in general there are different ways to set up a CMake project. The readme or some kind of documentation should tell you how to use it, if it's not obvious.
-
Trevor Boyd Smith almost 6 years@super i guess this is not so generic. feel free to edit my solution. the point of my solution is that you have to have at least one
install()
function call in yourcmake
project. So my solution attempts to provide a MCVE to demonstrate thecmake
function API usage forinstall()
. -
Mizux almost 6 yearstake a look at GNUInstallDirs built-in module also.. Then define config.cmake file also...
-
truthadjustr about 4 yearsThis answer helps a lot. Thank you, soldier! Too much gung ho for a generic solution that fails to spark a learning aha moment is pure evil. I believe in the strive for a generic solution in certain domains, but given the context that software build systems is an infant piece of engineering, it is better to expose the primitives necessary for new constructions.
-
Trevor Boyd Smith over 3 years@eigenfield thank you for understanding the reason i wrote this up (i.e. get something going that is easy to understand). the kind words are a nice counter balance to the criticisms of 'your solution is not generic'. i think the idea of "strive for generic solution" is a good idea... which is what i do in most of my code (because building robust generic solutions are 2-10x more lines and can be 2-10x harder to understand and can take 2x-10x more time to develop... and more importantly... most code does not need robust generic solutions).