autotool,libtool实践二
来源:互联网 发布:淘宝上什么内衣牌子好 编辑:程序博客网 时间:2024/06/05 11:45
简单的例子:
我们使用strip.c、procpath.c创建动态库libstrip.dll
然后编译ah.c并连接libstrip.lib产生执行程序ah.exe
Makefile.am如下:
lib_LTLIBRARIES=libstrip.lalibstrip_la_SOURCES=strip.c procpath.clibstrip_la_LDFLAGS=-no-undefined -avoid-versionbin_PROGRAMS=ahah_SOURCES=ah.c strip.hah_LDADD=libstrip.la
下面我逐条解释含义:
lib_LTLIBRARIES=libstrip.la
表示我们要创建一个库libstrip.la(一种抽象的库,根据不同的系统和参数它可以是一个静态库也可以是动态库,可以是.a,.lib,.dll)
libstrip_la_SOURCES=strip.c procpath.c
表示创建libstrip.la需要的源文件
libstrip_la_LDFLAGS=-no-undefined -avoid-version
链接的时候需要的链接产生。
-avoid-version告诉libtool不产生版本号。
-no-undefined告诉libtool可以产生一个dll,如果不加该参数将不会产生dll。
bin_PROGRAMS=ahah_SOURCES=ah.c strip.hah_LDADD=libstrip.la
这表示我们要产生一个执行程序,并且要链接libstrip。
这些文件都准备好了可以运行autoreconf命令来产生configure脚本。
autoreconf --install
下面我们看看怎么用vc来编译它,首先你需要cygwin,visual stdio 20xx,然后自己做一个脚本用来将cygwin-msvc-gcc转到vc的编译器cl.exe。
cygwin-msvc-gcc
#!/bin/shecho "cl $*" >> $0.log/cygdrive/E/Microsoft\ Visual\ Studio\ 12.0/VC/bin/cl $* >> $0.log
将脚本放入到PATH中,并且确保你设置了vc的环境变量
当然你需要一个configure.ac文件。
# -*- Autoconf -*-# Process this file with autoconf to produce a configure script.AC_PREREQ([2.69])AC_INIT([apphook], [0.1], [udsn2@sina.com])AC_CONFIG_MACRO_DIR([m4])AM_INIT_AUTOMAKE([foreign -Wall -Werror])AC_CONFIG_SRCDIR([src/ah.c])AC_CONFIG_HEADERS([config.h])AM_PROG_ARLT_PREREQ([2.4.0])LT_INIT([disable-static win32-dll dlopen])AC_PROG_LIBTOOL# Checks for programs.AC_PROG_CC# Checks for libraries.# Checks for header files.# Checks for typedefs, structures, and compiler characteristics.# Checks for library functions.AC_CONFIG_FILES([Makefile src/Makefile po/Makefile.in])AC_OUTPUT
具体的含义不解释了,详细见”configure.ac的编写“。
下面就可以开始编译了
./configure --host=cygwin-msvcmake
我将编译过程中执行的命令都俘获下来,它看上去像下面这样:
../libtool --tag=CC --mode=compile /cygdrive/g/source/apphook/compile cygwin-msvc -gcc -DHAVE_CONFIG_H -I. -I.. -DDLL_EXPORT -DWIN32 -g -c -o strip.lo strip.c cl -DHAVE_CONFIG_H -I. -I.. -DDLL_EXPORT -DWIN32 -g -c strip.c -DDLL_EXPORT -DPIC./libtool --tag=CC --mode=compile /cygdrive/g/source/apphook/compile cygwin-msvc -gcc -DHAVE_CONFIG_H -I. -I.. -DDLL_EXPORT -DWIN32 -g -c -o procpath.lo procpath.c cl -DHAVE_CONFIG_H -I. -I.. -DDLL_EXPORT -DWIN32 -g -c procpath.c -DDLL_EXPORT -DPIC./libtool --tag=CC --mode=link /cygdrive/g/source/apphook/compile cygwin-msvc-gc c -g -no-undefined -avoid-version -o libstrip.la -rpath /usr/local/lib strip.lo procpath.lo cl -o .libs/libstrip.dll .libs/strip.obj .libs/procpath.obj -link -dll./libtool --tag=CC --mode=link /cygdrive/g/source/apphook/compile cygwin-msvc-gcc -o ah.exe ah.obj libstrip.la cl -g -o .libs/ah.exe ah.obj ./.libs/libstrip.lib
按说cl不应该能识别-g -o -dll -link等产生,并产生正确的结果。但是事实上这个确实可以工作。根据稳妥的做法是在cygwin-msvc-gcc中做参数翻译工作。
- autotool,libtool实践二
- using libtool for libraries, autotool versioning
- autotool编译实践
- autotool
- AUTOTOOL
- libtool
- libtool
- Libtool
- libtool
- libtool
- libtool
- libtool
- libtool
- autotool Makefile
- Autotool使用
- autotool总结
- 《Autotools - GNU Autoconf, Automake与Libtool实践者指南》
- autotool学习和使用
- 《应试教育的死穴,恰在于堵死了孩子“犯错”的空间》读后感
- 一致性hash算法 - consistent hashing
- testng测试dao类,事务的添加
- Android GridView常用属性
- EL表达式 参考手册
- autotool,libtool实践二
- 字符串包含引号,q-quote
- OpenCV 2.4+ C++ SVM介绍
- 《从零开始学Swift》学习笔记(Day 41)——类的继承
- [leetcode]Valid Anagram
- MVC 权限验证Filter
- git代码和版本流程控制
- commons-codec中[md5,sha,base64加密算法]的实现demo
- Android读取SeekBar数值方法