Ubuntu vs code生成自己的动态链接库

本文介绍如何使用CMake进行项目的构建与安装,包括将头文件和动态链接库放置到指定目录,以及如何通过终端命令完成项目的配置、构建和安装过程。

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

注意:在VScode中编译完了之后需要删除build 不然会出错,同样在这里编译完了还想在vscode里面使用这里也需要删除

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Android_ros_web

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值