1、# 1、头文件在这里 hello.h 放到 /usr/local/include
install(FILES ${PROJECT_SOURCE_DIR}/include/hello.h DESTINATION /home/ding/usr/local/include)
2、具体用了动态链接库 可以封装? libhellow.so 放到 /usr/local/lib/
install( TARGETS hello LIBRARY DESTINATION /home/ding/usr/local/lib)
3、使用时,只需要添加上头文件和动态链接库就可以在自己的代码里面使用了。
4、先在build 下打开终端输入
cmake ..
出现:
ding@ding-desktop:~/vscode/cmake_practice/build$ cmake ..
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ding/vscode/cmake_practice/build
然后输入
sudo make install
出现
ding@ding-desktop:~/vscode/cmake_practice/build$ sudo make install
[sudo] ding 的密码:
Scanning dependencies of target hello
[ 25%] Building CXX object CMakeFiles/hello.dir/src/hello.cpp.o
[ 50%] Linking CXX shared library libhello.so
[ 50%] Built target hello
Scanning dependencies of target sayhello
[ 75%] Building CXX object CMakeFiles/sayhello.dir/useHello.cpp.o
[100%] Linking CXX executable sayhello
[100%] Built target sayhello
Install the project...
-- Install configuration: "Release"
-- Up-to-date: /home/ding/usr/local/include/hello.h
-- Installing: /home/ding/usr/local/lib/libhello.so
本文介绍如何使用CMake进行项目的构建与安装,包括将头文件和动态链接库放置到指定目录,以及如何通过终端命令完成项目的配置、构建和安装过程。
1791

被折叠的 条评论
为什么被折叠?



