最近在学习Cmake,在学习的过程中遇到一个问题:
安装共享库和头文件,在CMakeList.txt中添加了如下命令
INSTALL(TARGETS hello hello_static
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
INSTALL(FILES hello.h DESTINATION include/hello)
于是兴致勃勃的进行安装
cmake -DCMAKE_INSTALL_PREFIX=/usr ..
make
make install
然而到了最后的make install
总是报错
[ 50%] Built target hello
[100%] Built target hello_static
Install the project...
-- Install configuration: ""
-- Installing: /usr/lib/libhello.so.1.2
CMake Error at lib/cmake_install.cmake:48 (file):
file INSTALL cannot copy file
"/home/cambricon/cmake/learn/t3/build/lib/libhello.so.1.2" to
"/usr/lib/libhello.so.1.2".
Call Stack (most recent call first):
cmake_install.cmake:37 (include)
Makefile:61: recipe for target 'install' failed
make: *** [install] Error 1
对于这样的问题我也是一头雾水,后来查阅后发现解决办法很简单。。。。。。
sudo make install
加上sudo就可以了
So rookie I am.
-- Install configuration: ""
-- Installing: /usr/lib/libhello.so.1.2
-- Installing: /usr/lib/libhello.so.1
-- Installing: /usr/lib/libhello.so
-- Installing: /usr/lib/libhello.a
-- Installing: /usr/include/hello/hello.h
如上就解决了安装的问题。