RPM打包C++程序实例

24 篇文章 0 订阅

1.首先找到打包目录

 

$ rpm --showrc|grep _topdir
-14: _builddir  %{_topdir}/BUILD
-14: _rpmdir    %{_topdir}/RPMS
-14: _sourcedir %{_topdir}/SOURCES
-14: _specdir   %{_topdir}/SPECS
-14: _srcrpmdir %{_topdir}/SRPMS
-14: _topdir    %{_usrsrc}/redhat
$ rpm --showrc|grep _usrsrc
-14: _topdir    %{_usrsrc}/redhat
-14: _usrsrc    %{_usr}/src
$ rpm --showrc|grep _usr
-14: _defaultdocdir     %{_usr}/share/doc
-14: _topdir    %{_usrsrc}/redhat
-14: _usr       /usr
-14: _usrsrc    %{_usr}/src


一般是在/usr/src/redhat目录下

 

2.编写spec文件

hello.spec

 


%define debug_package %{nil}
Summary:    hello world rpm package
Name:       hello
Version:    0.1
Release:    1
Source:     hello-0.1.tar.gz
License:    GPL
Packager:   amoblin
Group:      Application
URL:        http://www.ossxp.com
#BuildRoot:  /usr/src/redhat/BUILD/hello-0.1/ BuildRoot 代表最终的安装目录。换言之,如果 wget 最终安装在 /usr/local/bin/wget 和 /usr/local 中的其他子目录下,比如文档安装在 /usr/local/man 下,那么在 RPM 构建过程中 BuildRoot 代表 /usr/local。一旦设定了 BuildRoot,就可以使用 RPM_BUILD_ROOT 环境变量访问其值。应该始终在 spec 文件中设置 BuildRoot 并检查该目录的内容,确认包即将安装的内容。
%description
This is a software for making your life more beautiful!

%prep
%setup -q
#%setup -q 是一个 %prep 宏,用于自动解压 Source 中的特定 tarball 压缩文件


%build
g++ -o hello hello.cpp

%install
install -m 755 hello /usr/local/bin/hello

%files
/usr/local/bin/hello

 

 

 

把写好的SPEC文件放入SPECS文件夹里

 

 

 

3.编写源程序

随便找个地方新建文件夹 hello-0.1,然后编写hello.cpp。

 

#include<iostream>
using namespace std;
int main()
{
	cout<<"Hello World!"<<endl;
}

 

打包hello-0.1文件夹,并把hello-0.1.tar.gz 放在SOURCES文件夹下

 

$ tar zcvf hello-0.1.tar.gz hello-0.1
hello-0.1/
hello-0.1/hello.c
$ mv hello-0.1.tar.gz /usr/src/redhat/SOURCES

 

4.打包

 

在SPECS目录下进行打包

 

5.验证

 

验证下是否成功了

参考:https://www.ibm.com/developerworks/cn/linux/l-rpm1/index.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值