linux程序安装包----动态链接库的自动编译与安装
2013-07-16 01:32
507 查看
制作linux下到安装包,常见的是.gz等这样的压缩包,在制作这样到安装文件到时候,可以从一个简单到例子实现:
--src(目录)
------helloworld.c
------inter.c
--lib(目录)
------maxnum.c
--include(目录)
------helloworld.h
------inter.h
------maxnum.h
一. 进入src目录进行相关配置
(1). helloworld.c
#include "helloworld.h"
#include "inter.h"
#include <stdio.h>
int main()
{
test_print();
return 0;
}
void test_print()
{
int num1 = 1;
int num2 = 2;
int max_num = max(num1, num2);
printf("max_num: %d ", max_num);
print(max_num);
}
(2). inter.c
#include "inter.h"
int print(int num)
{
printf("HAHA: num: %d\n", num);
return 0;
}
(3) Makefile.am
AUTOMAKE_OPTIONS=foreign
INCLUDES=-I ../include
bin_PROGRAMS=hello
hello_SOURCES=helloworld.c inter.c
hello_LDADD = ../lib/libmaxnum.la
二。进入lib 目录配置
(1)maxnum.c
#include "maxnum.h"
int max(int first, int second)
{
return first > second ? first : second;
}
(2) Makefile.am
AUTOMAKE_OPTIONS=foreign
INCLUDES = -I ../include
noinst_LTLIBRARIES = libmaxnum.la
libmaxnum_la_SOURCES = maxnum.c
三. 进入include目录配置
(1) helloworld.h
#ifndef __HELLOWORLD_H__
#define __HELLOWORLD_H__
extern int max(int first, int second);
#endif
(2) inter.h
#ifndef __INTER_H__
#define __INTER_H__
#include <stdio.h>
void test_print();
#endif
(3) maxnum.h
#ifndef __MAXNUM_H__
#define __MAXNUM_H__
int max(int first, int second);
#endif
四。返回主目录下,进行相关配置
(1) Makefile.am
AUTOMAKE_OPTIONS=foreign
SUBDIRS=lib src
五。 运行相关操作
(1) autoscan 生成configure.scan, 将其变成configure.in, 采用到命令: mv configure.scan configure.in, 修改configure.in
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.68])
AC_INIT(hello, 1.1, [liuz@163.com])
AC_CONFIG_SRCDIR([src/helloworld.c])
#AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE
# Checks for programs.
AC_PROG_CC
# Checks for libraries.
# FIXME: Replace `main' with a function in `-lcurl':
#AC_CHECK_LIB([curl], [main])
AC_PROG_LIBTOOL
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
#AC_CONFIG_FILES([Makefile
# lib/Makefile
# src/Makefile])
AC_OUTPUT(Makefile
lib/Makefile
src/Makefile)
(2) aclocal 生成相关到文件
(3)libtoolize -f -c 生成和lib库相关信息
(4) autoconf
(5) automake --add-missing
(6) 经过上述步骤后,就可以生成我们需要到安装到文件,即: make dist 则生成我们需要到 hello-1.1.tar.gz 文件
(7) 在第(5)后,可以先安装该文件,
1. ./configure 配置相关环境,生存Makefile文件
2. sudo make 编译makefile
3. sudo make install 则安装我们到文件,此时可以敲入: hello, 则可以显示我们到运行结果
4. sudo make uninstal 则卸载安装文件
--src(目录)
------helloworld.c
------inter.c
--lib(目录)
------maxnum.c
--include(目录)
------helloworld.h
------inter.h
------maxnum.h
一. 进入src目录进行相关配置
(1). helloworld.c
#include "helloworld.h"
#include "inter.h"
#include <stdio.h>
int main()
{
test_print();
return 0;
}
void test_print()
{
int num1 = 1;
int num2 = 2;
int max_num = max(num1, num2);
printf("max_num: %d ", max_num);
print(max_num);
}
(2). inter.c
#include "inter.h"
int print(int num)
{
printf("HAHA: num: %d\n", num);
return 0;
}
(3) Makefile.am
AUTOMAKE_OPTIONS=foreign
INCLUDES=-I ../include
bin_PROGRAMS=hello
hello_SOURCES=helloworld.c inter.c
hello_LDADD = ../lib/libmaxnum.la
二。进入lib 目录配置
(1)maxnum.c
#include "maxnum.h"
int max(int first, int second)
{
return first > second ? first : second;
}
(2) Makefile.am
AUTOMAKE_OPTIONS=foreign
INCLUDES = -I ../include
noinst_LTLIBRARIES = libmaxnum.la
libmaxnum_la_SOURCES = maxnum.c
三. 进入include目录配置
(1) helloworld.h
#ifndef __HELLOWORLD_H__
#define __HELLOWORLD_H__
extern int max(int first, int second);
#endif
(2) inter.h
#ifndef __INTER_H__
#define __INTER_H__
#include <stdio.h>
void test_print();
#endif
(3) maxnum.h
#ifndef __MAXNUM_H__
#define __MAXNUM_H__
int max(int first, int second);
#endif
四。返回主目录下,进行相关配置
(1) Makefile.am
AUTOMAKE_OPTIONS=foreign
SUBDIRS=lib src
五。 运行相关操作
(1) autoscan 生成configure.scan, 将其变成configure.in, 采用到命令: mv configure.scan configure.in, 修改configure.in
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.68])
AC_INIT(hello, 1.1, [liuz@163.com])
AC_CONFIG_SRCDIR([src/helloworld.c])
#AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE
# Checks for programs.
AC_PROG_CC
# Checks for libraries.
# FIXME: Replace `main' with a function in `-lcurl':
#AC_CHECK_LIB([curl], [main])
AC_PROG_LIBTOOL
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
#AC_CONFIG_FILES([Makefile
# lib/Makefile
# src/Makefile])
AC_OUTPUT(Makefile
lib/Makefile
src/Makefile)
(2) aclocal 生成相关到文件
(3)libtoolize -f -c 生成和lib库相关信息
(4) autoconf
(5) automake --add-missing
(6) 经过上述步骤后,就可以生成我们需要到安装到文件,即: make dist 则生成我们需要到 hello-1.1.tar.gz 文件
(7) 在第(5)后,可以先安装该文件,
1. ./configure 配置相关环境,生存Makefile文件
2. sudo make 编译makefile
3. sudo make install 则安装我们到文件,此时可以敲入: hello, 则可以显示我们到运行结果
4. sudo make uninstal 则卸载安装文件
相关文章推荐
- Linux程序安装之编译安装
- Linux下通过源码编译安装程序(configure/make/make install的作用 )
- Linux下通过源码编译安装程序
- Linux下用gcc编译安装程序
- 一键安装MySQL5.1.45,全自动安装MySQL SHELL程序(编译安装)
- linux程序管理4 编译安装
- linux下通过源代码包编译安装程序
- Linux下通过源码编译安装程序
- libevent源码安装及Linux自动编译功能总结
- linux程序源码编译安装
- ACE在linux下编译安装(附带test程序)
- 在 Linux 中自动生成 Cordova/Phonegap for Android 的 APK 安装程序
- Linux程序编译时自动添加git或SVN版本
- linux下编译安装程序的路径说明
- Linux程序源码编译安装的configure配置详解
- linux下编译安装程序的路径说明
- Linux下通过源码编译安装程序
- linux 编译c程序与动态链接库
- linux RHEL x86_64bit 系统安装 32bit兼容库 和 编译32bit程序
- Linux程序源码编译安装的configure配置详解