每天学五分钟 Liunx 1000 | 软件篇:源码安装
软件安装流程
[root@lianhua tarball]$ cat hello.cpp
#include <stdio.h>
#include "thanks.h" int main(void)
{
printf("Hello World\n");
thanks(); return 0;
}
[root@lianhua tarball]$ cat thanks.cpp
#include <stdio.h> int thanks(void)
{
printf("thanks lianhua, I love you\n"); return 0;
}
[root@lianhua tarball]$ cat thanks.h
int thanks();
[root@lianhua tarball]$ gcc -c hello.cpp
[root@lianhua tarball]$ ll
total 16
-rw-r--r-- 1 root root 117 May 10 22:44 hello.cpp
-rw-r--r-- 1 root root 1560 May 10 22:45 hello.o
-rw-r--r-- 1 root root 80 May 10 22:45 thanks.cpp
-rw-r--r-- 1 root root 14 May 10 22:44 thanks.h
[root@lianhua tarball]$ gcc -o hello hello.o
hello.o: In function `main':
hello.cpp:(.text+0xf): undefined reference to `thanks()'
collect2: error: ld returned 1 exit status
[root@lianhua tarball]$ gcc -c hello.cpp thanks.cpp
[root@lianhua tarball]$ ll
total 20
-rw-r--r-- 1 root root 117 May 10 22:44 hello.cpp
-rw-r--r-- 1 root root 1560 May 10 22:46 hello.o
-rw-r--r-- 1 root root 100 May 10 22:46 thanks.cpp
-rw-r--r-- 1 root root 14 May 10 22:44 thanks.h
-rw-r--r-- 1 root root 1520 May 10 22:46 thanks.o
[root@lianhua tarball]$ gcc -o hello hello.o thanks.o
[root@lianhua tarball]$ ll
total 32
-rwxr-xr-x 1 root root 8552 May 10 22:47 hello
-rw-r--r-- 1 root root 117 May 10 22:44 hello.cpp
-rw-r--r-- 1 root root 1560 May 10 22:46 hello.o
-rw-r--r-- 1 root root 100 May 10 22:46 thanks.cpp
-rw-r--r-- 1 root root 14 May 10 22:44 thanks.h
-rw-r--r-- 1 root root 1520 May 10 22:46 thanks.o
[root@lianhua tarball]$ file hello
hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=1801febeffa3328a578dac21ee994dd50893ed3f, not stripped
[root@lianhua tarball]$ ./hello
Hello World
thanks lianhua, I love you
静态函数库的可执行文件
[root@lianhua tarball]$ ar rcs liblianhua.a thanks.o
[root@lianhua tarball]$ ll
total 36
...
-rw-r--r-- 1 root root 1668 May 10 23:09 liblianhua.a
[root@lianhua tarball]$ gcc hello.cpp -llianhua -L/root/hxia/tarball
[root@lianhua tarball]$ gcc hello.cpp -llianhua -L/root/hxia/tarball -o lianhua
[root@lianhua tarball]$ ll
total 60
-rwxr-xr-x 1 root root 8552 May 10 22:47 hello
-rw-r--r-- 1 root root 117 May 10 22:44 hello.cpp
-rw-r--r-- 1 root root 1560 May 10 22:46 hello.o
-rwxr-xr-x 1 root root 8552 May 10 23:11 lianhua
-rw-r--r-- 1 root root 1668 May 10 23:09 liblianhua.a
-rw-r--r-- 1 root root 100 May 10 22:46 thanks.cpp
-rw-r--r-- 1 root root 14 May 10 22:44 thanks.h
-rw-r--r-- 1 root root 1520 May 10 22:46 thanks.o
[root@lianhua tarball]$ ./lianhua
Hello World
thanks lianhua, I love you
动态函数库的可执行文件
[root@lianhua shared]$ gcc -fPIC -shared thanks.cpp -o liblianhua.so
[root@lianhua shared]$ ll
total 20
-rw-r--r-- 1 root root 117 May 10 23:18 hello.cpp
-rwxr-xr-x 1 root root 8112 May 10 23:20 liblianhua.so
-rw-r--r-- 1 root root 100 May 10 23:18 thanks.cpp
-rw-r--r-- 1 root root 14 May 10 23:18 thanks.h
[root@lianhua shared]$ gcc hello.cpp -L. -llianhua -o hello
[root@lianhua shared]$ ll
total 32
-rwxr-xr-x 1 root root 8528 May 10 23:21 hello
-rw-r--r-- 1 root root 117 May 10 23:18 hello.cpp
-rwxr-xr-x 1 root root 8112 May 10 23:20 liblianhua.so
-rw-r--r-- 1 root root 100 May 10 23:18 thanks.cpp
-rw-r--r-- 1 root root 14 May 10 23:18 thanks.h
[root@lianhua shared]$ ./hello
./hello: error while loading shared libraries: liblianhua.so: cannot open shared object file: No such file or directory
[root@lianhua shared]$ cp libthanks.so /usr/lib/
[root@lianhua shared]$ vi /etc/ld.so.conf
[root@lianhua shared]$ ldconfig
[root@lianhua shared]$ ./hello
Hello World
thanks lianhua, I love you
[root@lianhua tarball]$ ldd hello
linux-vdso.so.1 => (0x00007ffcc9bec000)
libc.so.6 => /lib64/libc.so.6 (0x00007f4175126000)
/lib64/ld-linux-x86-64.so.2 (0x00007f41754f3000)
[root@lianhua tarball]$ ldd ./shared/hello
linux-vdso.so.1 => (0x00007fff7d9da000)
libthanks.so => /lib/libthanks.so (0x00007f6896b53000)
libc.so.6 => /lib64/libc.so.6 (0x00007f6896786000)
/lib64/ld-linux-x86-64.so.2 (0x00007f6896d55000)
每天学五分钟 Liunx 1000 | 软件篇:源码安装的更多相关文章
- Linux一些常用软件的源码安装
Sreen: wget ftp://ftp.gnu.org/pub/gnu/screen/screen-4.0.3.tar.gz .tar.gz cd screen- ./configure make ...
- 【程序包管理】Linux软件管理之src源码安装编译
在很多时候我们需要自定义软件的特性,这时就需要用到源码安装.那么,网上有很多编译源码的工具,那么,我们怎么知道别人使用的是什么工具呢.其实我也不知道(*^▽^*). 那么本篇博客主要是写C代码的源码安 ...
- salt源码安装软件和yum安装软件
上面简单列出了源码安装的sls文件书写思路. 涉及到一些固定的思路:如, 1,拷贝 解压安装时候需要依赖tar.gz存在 如果已安装则无需再次安装. 2,启动脚本 加入chk时候需要文件存在,如果已添 ...
- 搭建LNAMP环境(五)- PHP7源码安装Redis和Redis拓展
上一篇:搭建LNAMP环境(四)- 源码安装PHP7 一.安装Redis 1.创建redis用户组和用户 groupadd redis useradd -r -g redis -s /sbin/nol ...
- linux下源码安装软件
在linux下的很多软件都是通过源码包方式发布的,这样做对于最终用户而言,虽然相对于二进制软件包,配置和编译起来繁琐点,但是它的可移植性却好得多,针对不同的体系结构,软件开发者往往仅需发布同一份源码包 ...
- Linux源码安装软件
Linux环境下 源码编译安装软件 ==== 1. 下载,步骤略 ==== 2. 验证,部分官方下载同时提供签名,MD5,sha1,sha256等校验信息. $ gpg --verify gnupg- ...
- Android必学-异步加载+Android自定义View源码【申明:来源于网络】
Android必学-异步加载+Android自定义View源码[申明:来源于网络] 异步加载地址:http://download.csdn.net/detail/u013792369/8867609 ...
- linux操作之软件安装(二)(源码安装)
源码安装 linux上的软件大部分都是c语言开发的 , 那么安装需要gcc编译程序才可以进行源码安装. yum install -y gcc #先安装gcc 安装源码需要三个步骤 1) ./confi ...
- [svc]salt源码安装软件和yum安装软件
上面简单列出了源码安装的sls文件书写思路. 涉及到一些固定的思路:如, 1,拷贝 解压安装时候需要依赖tar.gz存在 如果已安装则无需再次安装. 2,启动脚本 加入chk时候需要文件存在,如果已添 ...
- Linux 之 软件安装-yum、rpm、源码安装
软件安装-yum.rpm.源码安装 参考教程:[千峰教育] 一.Yum安装软件: 基本说明: 1.yum相当于windows上面的360的软件中心,appstore,安卓的应用商店. 2.yum是re ...
随机推荐
- 关于Secure Hash Algorithm加密算法
一.概述 SHA(Secure Hash Algorithm)加密算法是一种广泛应用的密码散列函数,由美国国家安全局(NSA)设计,用于保障数据的安全性和完整性.SHA算法经历了多个版本的更新,目前主 ...
- 安装华企盾DSC防泄密软件:编辑文件不加密常见问题,运维工程师必看
1.先查看客户端日志主进程是否是加密进程.日志中是不是勾选智能半透明.加密类型是否有添加 2.用procmon监控保存的文件找出writefile的进程是否有添加,进程树是否有父进程,加密类型是否正确 ...
- SSM整合 tomcat报错: <严重 [RMI TCP Connection(22)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal 一个或多个筛选器启动失败。完整的详细信息将在相应的容器日志文件中找到>
前提:学了一个暑假 从Javaweb -> mybits ->spring -> spring-mvc 打算跟着网上ssm整合项目做一个项目 在完成最后一步spring对spring ...
- 面试官:说说MVCC的执行原理?
MVCC(Multi-Version Concurrency Control)是一种并发控制机制,用于解决数据库并发访问中,数据一致性问题.它通过在读写操作期间保存多个数据版本,以提供并发事务间的隔离 ...
- 【笔记】 springCloud-configServer配置中心
当然第一步还是得要了解啦! 介绍 做项目, 那么就少不了配置微服务架构中,配置文件众多,各个服务的配置文件也有可能不一样, Spring为我们提供了相应的配置中心组件--Spring Cloud co ...
- SQL注入Fuzzing字典
需要的自取 ' " # - -- ' -- --'; ' ; = ' = ; = -- \x23 \x27 \x3D \x3B' \x3D \x27 \x27\x4F\x52 SELECT ...
- 2023-05-19:汽车从起点出发驶向目的地,该目的地位于出发位置东面 target 英里处。 沿途有加油站,每个 station[i] 代表一个加油站, 它位于出发位置东面 station[i][
2023-05-19:汽车从起点出发驶向目的地,该目的地位于出发位置东面 target 英里处. 沿途有加油站,每个 station[i] 代表一个加油站, 它位于出发位置东面 station[i][ ...
- spring-cloud-alibaba项目打包
在父依赖中加入 <build> <plugins> <plugin> <groupId>org.springframework.boot</gro ...
- 第四部分_Shell脚本数组和其他变量
数组定义 ㈠ 数组分类 普通数组:只能使用整数作为数组索引(元素的下标) 关联数组:可以使用字符串作为数组索引(元素的下标) ㈡ 普通数组定义 可以切片 一次赋予一个值 #数组名[索引下标]=值 ar ...
- Web 全栈开发利器: 强大的在线 Cloud IDE
摘要:近年来,敏捷.DevOps的理念已逐步成为主流.基于云计算的开发环境也正获得越来越多开发者的青睐.不难想象,云端IDE已成未来的趋势. 学了Web全栈开发,就得动手实践,要动手,得先有开发环境. ...