瑕佷嬌鐢╝utomake宸ュ叿鍖呭緩绔嬩竴涓氦鍙夌紪璇戠殑鍏變韓搴撶殑Makefile
榪欓噷鐢ㄧ殑autoconf鏄?.67鐗堟湰錛屽湪debian涓嬪疄鐜?
濡傛灉鐗堟湰浣庯紝鍙互鐢╝pt-get install automake鏉ヨ鏈鏂扮殑鐗堟湰錛岃繕闇瑕乴ibtool,涔熼渶瑕佺敤apt-get install鏉ュ畨瑁呫?/p>
榪欓噷寤虹珛涓涓畝鍗曠殑鍑芥暟搴撴潵浠嬬粛錛?/p>
寤虹珛鐩綍rx,鍙婃簮鐮佺洰褰晄rc:
$mkdir rx
$mkdir rx/src
鍦╮x/src涓嬬紪杈憆x.c,rx.h涓や釜婧愭枃浠?
mybdebian:/home/myb/php/rx/src# cat rx.h
#ifndef __RX_H_
#define __RX_H_
int fun();
#endif
mybdebian:/home/myb/php/rx/src# cat rx.c
#include "rx.h"
int fun()
{
return 1234;
}
鍦╮x鐩綍鍜宺x/src鐩綍涓嬪垎鍒緩绔婱akefile.am鏂囦歡
rx鐩綍涓嬬殑Makefile.am涓洪《灞侻akefile.am鏂囦歡錛屽彧瑕佸寘鍚叾瀛樻斁婧愮爜鐨勫瓙鐩綍鍗沖彲錛屽唴瀹瑰涓嬶細
AUTOMAKE_OPTIONS=foreign
SUBDIRS=src
rx/src鐩綍涓嬬殑Makefile.am鍐呭濡備笅錛?/p>
AUTOMAKE_OPTIONS=foreign
lib_LTLIBRARIES=librx.la
librx_la_SOURCES=rx.cinclude_HEADERS=rx.h
鍏朵腑lib_LTLIBRARIES=鍚庨潰鐨?#8220;librx.la”涓鴻鐢熸垚鐨勫簱鏂囦歡鍚?蹇呴』鍐欐垚.la錛屼笉鑳芥槸.so錛屽疄闄呬細鐢熸垚librx.so鏂囦歡銆?/p>
涓嬮潰鐨刲ibrx_la鏄痩ibrx.la鎶?#8220;.”鎹㈡垚涓嬪垝綰?#8220;_”鍚庨潰鍔犱笂“_SOURCES=”錛岀瓑鍙蜂互鍚庝負婧愭枃浠跺悕縐幫紝澶氫簬涓涓椂鐢ㄧ┖鏍奸殧寮銆?/p>
include_HEADERS=鍚庨潰鐨勪負澶存枃浠訛紝鏄緵鍏跺畠紼嬪簭鍖呭惈鐢ㄧ殑錛宮ake install鏃朵細澶嶅埗鍒板畨瑁呯洰褰曠殑include 鐩綍涓?/p>
鍥炲埌涓婂眰鐩綍錛屼嬌鐢╝utoscan鎵弿婧愮爜鐩綍:
$autoscan
$ls
autoscan.log configure.scan Makefile.am src
鎶奵onfigure.scan鏀瑰悕鎴愪負configure.ac
$mv configure.scan configure.ac
AC_OUTPUT([Makefile
src/Makefile])
緙栬瘧榪欎釜鏂囦歡:
$vim configure.ac
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.67])
AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
AC_CONFIG_SRCDIR([src/rx.c])
AC_CONFIG_HEADERS([config.h])
# 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])
AC_OUTPUT
淇敼AC_INIT涓鍙ワ紝鍗蟲妸鍖呯殑鍏ㄥ悕銆佺増鏈彿鍙夿UG鎶ュ憡email鍦板潃娣諱笂錛屽錛?/p>
AC_INIT(rx2dlib,0.01,resound@163.com)
鍦ㄥ畠鍚庨潰鍔犱竴鍙?
AM_INIT_AUTOMAKE
榪欏彞璇濇槸蹇呴』鐨勩?/p>
鐢變簬榪欎釜鑴氭湰鏄敤浜庣敓鎴愬叡浜簱鐨勶紝鎵浠ヨ鍔犱竴鍙C_PROG_LIBTOOL鍦ˋC_PROG_CC鐨勪笅涓琛岋細
# Checks for programs.
AC_PROG_CC
AC_PROG_LIBTOOL
淇敼鍚庨潰鐨勯偅涓狝C_CONFIG_FILES璇彞錛屾敼鎴怉C_OUTPUT,騫舵妸鍚庨潰鐨勪竴鏉C_OUTPUT鍘繪帀錛?/p>
AC_OUTPUT([Makefile
src/Makefile])
榪欐牱錛宑onfigure.ac灝卞緩濂戒簡錛屼慨鏀瑰悗鐨勫唴瀹瑰涓?
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.67])
AC_INIT(rx2dlib,0.01,resound@163.com)
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([src/rx.c])
AC_CONFIG_HEADERS([config.h])
# Checks for programs.
AC_PROG_CC
AC_PROG_LIBTOOL
# Checks for libraries.
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_OUTPUT([Makefile
src/Makefile])
鐒跺悗鎸夐『搴忔墽琛?
$aclocal
$autoconf
$autoheader
$libtoolize --automake
$automake –-add-missing
configure.ac:13: installing `./config.guess'
configure.ac:13: installing `./config.sub'
configure.ac:6: installing `./install-sh'
configure.ac:6: installing `./missing'
src/Makefile.am: installing `./depcomp'
榪欐椂configure鑴氭湰宸茬粡鐢熸垚浜嗐?/p>
鍙互鐢ㄥ畠鏉ラ厤緗敓鎴怣akefile浜嗐?/p>
濡傛垜浠鐢熸垚浜ゅ弶緙栬瘧緇橝RM CPU浣跨敤鐨勫叡浜簱,榪欓噷鍋囪鎴戜滑瑕佷嬌鐢ㄧ殑緙栬瘧鍣ㄤ負arm-none-linux-gnueabi-gcc錛屽茍涓旀垜浠渶緇堝湪ARM鏉夸笂鎵ц鏃訛紝瑕佹妸搴撳畨瑁呭埌鐩爣鏉跨殑/usr/local/armrx2d鐩綍涓幓銆傚彲浠ヨ繖鏍烽厤緗?
$./configure --host=arm-none-linux-gnueabi --prefix=/usr/local/armrx2d$make
Make瀹屾垚鍚庡彲浠ュ埌src鐩綍涓嬮潰鐨勪竴涓殣钘忕洰褰?libs鐩綍涓湅鍒扮敓鎴愮殑搴撴枃浠訛細
mybdebian:/home/myb/php/rx/src/.libs# ls -l
鎬昏 20
-rw-r--r-- 1 root root 2368 04-19 22:48 librx.a
lrwxrwxrwx 1 root root 11 04-19 22:48 librx.la -> ../librx.la
-rw-r--r-- 1 root root 930 04-19 22:48 librx.lai
lrwxrwxrwx 1 root root 14 04-19 22:48 librx.so -> librx.so.0.0.0
lrwxrwxrwx 1 root root 14 04-19 22:48 librx.so.0 -> librx.so.0.0.0
-rwxr-xr-x 1 root root 5422 04-19 22:48 librx.so.0.0.0
-rw-r--r-- 1 root root 2228 04-19 22:48 rx.o
鎴戜滑鍐嶅洖鍒伴《灞傜洰褰曪紝鎵цmake install鍙互鑷姩瀹夎鐢熸垚鐨勫簱鍒?usr/local/armrx2d/lib鐩綍涓嬨?/p>
鑻ヤ嬌鐢╝utomake鏃跺嚭鐜頒笅闈㈤敊璇俊鎭?/p>
required file `./ltmain.sh' not found
鏄洜涓簂ibtool鏈厤緗細
瑙e喅鍔炴硶錛?/p>
$libtoolize --automake --debug --copy –force
鎴栵細
$libtoolize --automake
鐢╣db璋冭瘯鍔ㄦ侀摼鎺ュ簱
澶у閮界煡閬撳湪 Linux 鍙互鐢?gdb 鏉ヨ皟璇曞簲鐢ㄧ▼搴忥紝褰撶劧鍓嶆彁鏄敤 gcc 緙栬瘧紼嬪簭鏃惰鍔犱笂 -g 鍙傛暟銆?/p>
鎴戣繖綃囨枃绔犻噷灝嗚璁轟竴涓嬬敤 gdb 鏉ヨ皟璇曞姩鎬侀摼鎺ュ簱鐨勯棶棰樸?/p>
棣栧厛錛屽亣璁炬垜浠噯澶囪繖鏍風殑涓涓姩鎬侀摼鎺ュ簱錛?/p>
寮曠敤錛?/p>
搴撳悕縐版槸錛?ggg
鍔ㄦ侀摼鎺ュ簱鏂囦歡鍚嶆槸錛?libggg.so
澶存枃浠舵槸錛?get.h
鎻愪緵榪欐牱涓や釜鍑芥暟璋冪敤鎺ュ彛錛?/strong>
int get ();
int set (int a);
瑕佺敓鎴愯繖鏍蜂竴涓姩鎬侀摼鎺ュ簱錛屾垜浠鍏堢紪鍐欒繖鏍蜂竴涓ご鏂囦歡錛?/p>
/************鍏充簬鏈枃妗?*******************************************
*filename: get.h
*********************************************************************/
int get ();
int set (int a);
鐒跺悗鍑嗗榪欐牱涓涓敓鎴愬姩鎬侀摼鎺ュ簱鐨勬簮鏂囦歡錛?/p>
/************鍏充簬鏈枃妗?*******************************************
*filename: get.cpp
*********************************************************************/
#include
#include "get.h"
static int x=0;
int get ()
{
printf ("get x=%d\n", x);
return x;
}
int set (int a)
{
printf ("set a=%d\n", a);
x = a;
return x;
}
鐒跺悗鎴戜滑鐢?GNU 鐨?C/C++ 緙栬瘧鍣ㄦ潵鐢熸垚鍔ㄦ侀摼鎺ュ簱錛岀紪璇戝懡浠ゅ涓嬶細
寮曠敤錛?/p>
g++ get.cpp -shared -g -DDEBUG -o libggg.so
榪欐牱鎴戜滑灝卞噯澶囧ソ浜嗗姩鎬侀摼鎺ュ簱浜嗭紝涓嬮潰鎴戜滑緙栧啓涓涓簲鐢ㄧ▼搴忔潵璋冪敤姝ゅ姩鎬侀摼鎺ュ簱錛屾簮浠g爜濡備笅錛?/p>
/************鍏充簬鏈枃妗?*******************************************
*filename: pk.cpp
*********************************************************************/
#include
#include "get.h"
int main (int argc, char** argv)
{
int a = 100;
int b = get ();
int c = set (a);
int d = get ();
printf ("a=%d,b=%d,c=%d,d=%d\n",a,b,c,d);
return 0;
}
緙栬瘧姝ょ▼搴忕敤涓嬪垪鍛戒護錛屽鏋滃凡緇忔妸涓婇潰鐢熸垚鐨?libggg.so 鏀懼埌浜嗗簱鏂囦歡鎼滅儲璺緞鎸囧畾鐨勬枃浠剁洰褰曪紝姣斿 /lib 鎴?/usr/lib 涔嬬被鐨勶紝灝辯敤涓嬮潰榪欐潯鍛戒護錛?/p>
寮曠敤錛?/p>
g++ pk.cpp -o app -Wall -g -lggg
鍚﹀垯灝辯敤涓嬮潰榪欐潯鍛戒護錛?/p>
寮曠敤錛?/p>
g++ pk.cpp -o app -Wall -g -lggg -L`pwd`
涓嬮潰鎴戜滑灝卞紑濮嬭皟璇曚笂闈㈠懡浠ょ敓鎴愮殑 app 紼嬪簭鍚с傚鏋滃凡緇忔妸涓婇潰鐢熸垚鐨?libggg.so 鏀懼埌浜嗗簱鏂囦歡鎼滅儲璺緞鎸囧畾鐨勬枃浠剁洰褰曪紝姣斿 /lib 鎴?/usr/lib 涔嬬被鐨勶紝璋冭瘯灝遍『鍒╁畬鎴愶紝濡備笅錛?/p>
寮曠敤錛?/p>
#gdb ./app
GNU gdb 6.4-debian
Copyright 2005 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i486-linux-gnu"...Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1".
(gdb) b main /* 榪欐槸鍦ㄧ▼搴忕殑 main 澶勮緗柇鐐?*/
Breakpoint 1 at 0x804853c: file pk.cpp, line 7.
(gdb) b set /* 榪欐槸鍦ㄧ▼搴忕殑 set 澶勮緗柇鐐?*/
Function "set" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y /* 榪欓噷蹇呴』閫夋嫨 y 璋冭瘯紼嬪簭鎵嶄細璺熻釜鍒板姩鎬侀摼鎺ュ簱鍐呴儴鍘?*/
Breakpoint 2 (set) pending.
(gdb) run /* 寮濮嬭繍琛屾垜浠殑紼嬪簭錛岀洿鍒伴亣瑙佹柇鐐規椂鏆傚仠 */
Starting program: /data/example/c/app
Breakpoint 3 at 0xb7f665f8: file get.cpp, line 11.
Pending breakpoint "set" resolved
Breakpoint 1, main (argc=1, argv=0xbf990504) at pk.cpp:7
7 int a = 100;
(gdb) n /* 緇х畫鎵ц紼嬪簭鐨勪笅涓琛屼唬鐮?*/
8 int b = get ();
(gdb) n /* 紼嬪簭鎵ц鍒頒簡鎴戜滑鏂偣鎵鍦ㄧ殑鍔ㄦ侀摼鎺ュ簱浜?*/
get x=0
9 int c = set (a);
(gdb) n
Breakpoint 3, set (a=100) at get.cpp:11
11 printf ("set a=%d\n", a);
(gdb) list /* 鏌ョ湅褰撳墠浠g爜琛屽懆鍥寸殑浠g爜錛岃瘉鏄庢垜浠凡緇忚窡韙埌鍔ㄦ侀摼鎺ュ簱鐨勬簮浠g爜閲岄潰浜?*/
6 printf ("get x=%d\n", x);
7 return x;
8 }
9 int set (int a)
10 {
11 printf ("set a=%d\n", a);
12 x = a;
13 return x;
14 }
(gdb) n
set a=100
12 x = a;
(gdb) n
13 return x;
(gdb) n
14 }
(gdb) n
main (argc=1, argv=0xbf990504) at pk.cpp:10
10 int d = get ();
(gdb) n
get x=100
11 printf ("a=%d,b=%d,c=%d,d=%d\n",a,b,c,d);
(gdb) n
a=100,b=0,c=100,d=100
12 return 0;
(gdb) c
Continuing.
Program exited normally.
(gdb) quit /* 紼嬪簭欏哄埄鎵ц緇撴潫 */
濡傛灉鎴戜滑娌℃湁鎶婂姩鎬侀摼鎺ュ簱鏀懼埌鎸囧畾鐩綍錛屾瘮濡?lib閲岄潰錛岃皟璇曞氨浼氬け璐ワ紝榪囩▼濡備笅錛?/p>
寮曠敤錛?/p>
# gdb ./app
GNU gdb 6.4-debian
Copyright 2005 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i486-linux-gnu"...Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1".
(gdb) b main
Breakpoint 1 at 0x804853c: file pk.cpp, line 7.
(gdb) b set
Function "set" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 2 (set) pending.
(gdb) run /* 铏界劧璋冭瘯鎿嶄綔閮戒竴鏍鳳紝浣嗙▼搴忔墽琛屽け璐?*/
Starting program: /data/example/c/app
/data/example/c/app: error while loading shared libraries: libggg.so: cannot open shared object file: No such file or directory
Program exited with code 0177.
(gdb) quit
http://os.chinaunix.net/a2007/0830/976/000000976152.shtml