EDN首页   博客首页 用户登陆  |  注册
aaa
发表于 2008/10/12 16:34:24

0

关于投票

shell函数的使用【原】

2008年10月11日 星期六 21:11

      这周开始在老大的本本上试了下我前面写的自动编译脚本,发现我./jiaoben_test时cygwin不识别我里面用到的source这个命令,呵呵,后来我自己写了个脚本专门试验了source这个命令,发现他是用source jiaoben_test时可以识别,呵呵,然后我跟他说,也用source来试试我那个脚本,呵呵,果然如此,通过,很high哦。

      老大之前看了我写的脚本,说我写得太多了,很多是可以用一个函数来实现的,这样可以省得重复,可是我又不会用shell里面的函数,没办法,学,呵呵,其实很简单的。

        shell里面的函的语法数定义: 函数使用以下2种形式。

    function FUNCTION { COMMANDS; }   或者FUNCTION () { COMMANDS; } 。如果你要传参数,就直接用FUNCTION 你函数里面要用的参数

   PS:函数里面是不能直接用你上面蓝色部分的参数的 要用$1等来代替你的参数哦。这是shell的特色吧

系统分类: 嵌入式  |  用户分类: Linux学习  |  标签: shell函数  |  来源: 原创  | 

点击查看原文

发表评论 阅读全文(528) | 回复(0)

发表于 2008/10/12 16:33:31

0

关于投票

写自动编译的脚本所遇问题【原】

2008年10月03日 星期五 19:11

       好不容易有时间学习linux,今天在公司弄个脚本,让它自动对我们的工程文件编译,而不需要我们自己手动去输入命令,特别是宏开关,因为客户之多,宏开关也就多,我们老大国庆前跟我说有时间好好研究下脚本,并给我一个范本,呵呵,今天下午特地跑到公司来研究研究,呵呵,还真碰到一些问题:

1. 如何比较两个字符串相等;举例:

if [ "$test"x = "test"x ]; then

这里的关键有几点:

1 使用单个等号

2 注意到等号两边各有一个空格:这是unix shell的要求

3 注意到"$test"x最后的x,这是特意安排的,因为当$test为空的时候,上面的表达式就变成了x = testx,显然是不相等的。而如果没有这个x,表达式就会报错:[: =: unary operator expected

2. $1...表示什么;举例:

先做一个shell: w2.sh
=======================================
#!/bin/bash

echo $1
echo $2
echo $3
=======================================
在Linux下: chmod +x w2.sh
./w2.sh   hello boobooke   video
执行结果:
hello
boobooke
video
清楚了吧? $1是传递给该shell脚本的第一个参数,$2是传递给该shell脚本的第二个参数,以此类推。

3. 如何打开文件中的宏,举例:

比如我要打开test.h中的宏 #define __TEST__

TestStrings="__TEST__"

PATH="test.h的目录"

sed -ie "s/^\/\/${TestStrings}\s*/${TestStrings}/" $PATH/test.h

关闭test.h中的宏 #define __TEST__

sed -ie "s/^${TestStrings}\s*/\/\/${TestStrings}/" $PATH/test.h

注:必须加上i,否则它不会改变源文件的内容,只会把改变后的内容在终端中显示

系统分类: 嵌入式  |  用户分类: Linux学习  |  标签: shell  |  来源: 无分类  | 

点击查看原文

发表评论 阅读全文(456) | 回复(0)

发表于 2008/10/12 16:32:03

0

关于投票

linux中“男人”几个常用命令[原]

2008年09月21日 星期日 11:54

今天早上一起来,肚子疼得很厉害,本来打算去公司的,于是找了这个借口待在宿舍。也趁着这个宝贵时间学习linux相关,刚刚发现在man中有几个我以前不晓得的几个常用键哦。

我们的linux中2000条以上的命令,要把它们一一记住,很难的,所以man就经常使用,但是往往man出来的文档N长,这时我们可以通过搜索关键词迅速找到我们想要的,呵呵。见下:

空格键          向下翻页

[Page Down] 向下翻页

[Page Up]       向上翻页

[Home]    回到第一页

[End]        到最后一页

/string      向下查找string

?string     向上查找string

n              查找下一个string

N              查找上一个string

q               退出

红色部分是我很少用的几个键,呵呵,这次应该记住了哦。

系统分类: 嵌入式  |  用户分类: Linux学习  |  标签: man  |  来源: 原创  | 

点击查看原文

发表评论 阅读全文(427) | 回复(0)

发表于 2008/10/12 16:20:02

0

关于投票

教你Ubuntu中如何用命令设置时间[原]

2008年09月06日 星期六 23:20

由于我不用虚拟机时,经常是挂起旗下的Ubuntu,这样有一个问题,每当重新启动Ununtu时系统时间会从上次挂起时的时间开始;这样就不方便我看时间,于是想手动设置它,网上搜了半天,本来date使可以设置时间的,经实验发现不行,情况如下:
lammy@lammy-desktop:~$ date 090522572008.00
date: 无法设置日期: 操作不允许
2008年 09月 05日 星期五 22:57:00 CST
lammy@lammy-desktop:~$ date
2008年 09月 03日 星期三 05:00:19 CST

本来是设好了哈,怎么又说操作不允许呢,想了半天,是不是权限问题呢,马上在前面加上 sudo,呵呵,搞定咯。
lammy@lammy-desktop:~$ sudo date 090523012008.30
2008年 09月 05日 星期五 23:01:30 CST
lammy@lammy-desktop:~$ date
2008年 09月 05日 星期五 23:01:33 CST

附:在Ubuntu上root用户是不向我们开放的,所以当普通用户想得到超级用户的权限时,要在命令前加上sudo。man sudo 一下会发现其中一句话就明白了: sudo allows a permitted user to execute a command as the superuser or another user, as specified in the sudoers file.

系统分类: 嵌入式  |  用户分类: Linux学习  |  标签: date  |  来源: 原创  | 

点击查看原文

发表评论 阅读全文(671) | 回复(0)

发表于 2007/12/29 21:11:00

1

关于投票

linux汇编学习『原』

    近来这些日子好像找到了昔日学习的劲头,希望能继续延续下去,让自己的大四过得充实些。
    以下是这两天的汇编学习笔记:

  as来调试汇编程序时,要借助-gstabs参数来将调试信息汇编进可执行文件中;这里面要注意的是如果使用gcc的话,则是借助-g参数来实现。

  在调试的过程中,如果要设置断点时,不能按照调试c语言的方法来设置断点,必须用如下的格式:b『或break *_start『或其它自定义的起始标签』+_start的行数;并且起始标签后的第一条语句必须是nop『意思是空操作』,否则你所设的断点无效,这也是GUN汇编器的缺陷。

  我们写的汇编程序中如果调用了C库函数时;连接时必须把库文件链接到目标代码中去;在linux系统中,有两种方法:一是静态连接,它是把目标代码直接连接到可执行的文件中去,势必会创建很大的可执行文件;二是动态连接,运行时它是由操作系统调用动态连接库,这样它可以节省空间,而且多个程序可以共享动态连接库。但是如果用gcc来编译,就可以省去这部分,因为gcc编译器是自动连接所需的C库文件

  linux下的汇编程序是由3个常用的段组成,分别是数据段、bss段、代码段。所有的汇编程序必须有代码段『其格式:.section .text』,该区域是放指令码的地方;数据段它是可选的『其格式:.section .data.rodata』,用.data命令声明的数据段,这个段的任何数据元素都保留在内存中并且可以被汇编语言的指令读取和写入,如果用.rodata命令声明的数据段,这个段中的任何数据元素只能按照只读『read only』的方式访问bss段声明的数据『其格式:.section .bss』是用0null来初始化的,它有一个好处就是这部分的数据不在可执行程序中,所以它不像data段声明多少数据就占用多少空间。

  linux下的数前面必须加上美元符号$才能是立即数。

  linux下汇编程序中内存的变址查询模式:

base_address(offset_address,index,size)à base_address + offset_address + index * size

  当使用标签引用内存位置中包含的数据值时,前面必须通过美元符号$才能获得数据值的地址。


系统分类: 嵌入式  |  用户分类: Linux学习  |  标签: as gun  |  来源: 原创  | 

点击查看原文

发表评论 阅读全文(715) | 回复(0)

发表于 2007/12/27 19:06:31

2

关于投票

ld之解『原』

    找工作前学习网上流行的《S3C2410完全开发流程》时,碰到这么一个问题,就是Makfile中有一个出现了ld,当时我不知道为什么要这句,试着把ld那句注释掉,结果死活不能make通过;当时查了N多资料,就是没找到。今天下午上自习时,仔细看了下昨天借的Richard Blum著《Assembly Language》『中文版』;呵呵,仔细看了两个小时,没白看,无意中把前面的问题给解决了,呵呵。
    因为汇编程序被转化成可执行文件时,连接器必须知道指令码中的起始地址。为了解决这个问题,GUN汇编器声明一个默认标签,或者说是标志符,它就是_start。如果连接器找不到_start,就会生成错误信息;错误信息我就不贴出来了。当然也可以使用_start以为的标签作为起始地点;但是必须通过-e来说明。
    比如有一个汇编文件cpuid.s;它转化成可执行的文件cpuid。是通过:
    as -o cpuid.o cpuid.s   #起始标签为_start
    ld -o cpuid cpuid.o
或:
    as -o cpuid.o cpuid.s   #起始标签为_start1
    ld -e _start1 -o cpuid cpuid.o
    我们知道GCC它不仅能编译汇编语言,还能编译高级语言如C语言。那么GCC它又是以什么标签来作为起始地址?我们知道C语言中至少有main函数;所以main便是gcc要找的标签。如果要用gcc来编译上面的cpuid.s,必须把源文件中的
    .globl _start
    _start:  
改为.globl main
    main:
    不知道大家明白了不。

系统分类: 嵌入式  |  用户分类: Linux学习  |  标签: ld  |  来源: 原创  | 

点击查看原文

发表评论 阅读全文(912) | 回复(0)

发表于 2007/12/18 18:20:40

1

关于投票

“考考你的C指针”题解『原』

    前面几天我贴下《C语言解惑》的一个C指针程序,呵呵,放在我的百度空间和EDN空间,总算我百度的一个网友做出来了。先不说答案,且听我如果解答这怪题。

#include<stdio.h>
char *c[]={
    "ENTER",
    "NEW",
    "POINT",
    "FIRST"
};
char **cp[]={c+3,c+2,c+1,c};
char ***cpp=cp;
int main(void)
{
    printf("%s",**++cpp);
    printf("%s   ",*--*++cpp+3);
    printf("%s",*cpp[-2]+3);
    printf("%s\n",cpp[-1][-1]+1);
    return 0;
}

呵呵,我解释下char *c[]c是一个数组名,数组里面的元素是一个指针,这个指针指向的是一个字符串cpp的结构用语言描述下,cpp是一个地址,这个地址里面的内容放的是cpcp是个什么东西呢,也是一个地址,这个地址里面的内容放的是c+3,而c+3也是一个地址,其地址是字符串 FIRST\0 的首地址;现在我把cpp初始化的结构画出来,如下:


    相信大家应该可以解决这个程序问题,如果还不能,建议去看看《C和指针》。哦,对了,忘了说答案的,答案是POINTER  STEW


系统分类: 嵌入式  |  用户分类: Linux学习  |  标签: C语言解惑 C指针  |  来源: 原创  | 

点击查看原文

发表评论 阅读全文(1048) | 回复(0)

发表于 2007/12/16 13:48:47

1

关于投票

考考你的C指针『原』

    最近两天在图书馆发现一本《C语言解惑》,自己仔细的看了一下,写得不赖。我顺便把里面一道C指针题贴出来考考大家,过两天我再贴出答案;如果没什么把握建议你去看下《C语言解惑》,绝对值!!
#include<stdio.h>
char *c[]={
    "ENTER",
    "NEW",
    "POINT",
    "FIRST"
};
char **cp[]={c+3,c+2,c+1,c};
char ***cpp=cp;
int main(void)
{
    printf("%s",**++cpp);
    printf("%s   ",*--*++cpp+3);
    printf("%s",*cpp[-2]+3);
    printf("%s\n",cpp[-1][-1]+1);
    return 0;
}

系统分类: 嵌入式  |  用户分类: Linux学习  |  标签: C语言解惑 C指针  |  来源: 原创  | 

点击查看原文

发表评论 阅读全文(1405) | 回复(4)

发表于 2007/10/13 20:56:36

0

关于投票

魔鬼autotools升华使用[原]

    这几天没怎么出去跑宣讲会,因为那些公司我不感兴趣,感兴趣的公司说这两天会给我电话面试,等了N久,就是没有,真搞不懂我问题倒底出在哪,找工作归找工作; 我自己的感兴趣的嵌入式还得学,也够郁闷的,白天上自习看模拟数字,晚上会宿舍研究嵌入式linux,自从我成功把vivi移植后,一直想研究vivi怎么写,呵呵,倒好,发现N多问题,比如这么多文件,怎么编译,那么多的makefile,还有很多文件不是很清楚,怎么办,继续奋斗呗,我把图书关于嵌入式linux的书都翻遍了,发现讲这方面的实在太少了,真的想说那句话,linux真应该从娃娃抓起。好在发现在《嵌入式系统与应用开发》中有一小段篇幅是利用autotools来处理很多.c的软件,先前前面我讲过怎样处理一个.c的文件,呵呵,今天来玩玩多个.c的makefile的编写,好了,开始:

首先新建一个hello的文件夹,然后在hello下新建add和sub两个文件夹,在add下编写一个add.c,内容如下:
int add(int x,int y)
{
        return x+y;
}
在sub下编写一个sub.c的文件,内容如下:
int sub(int x,int y)
{
        return x-y;
}
在hello下编写main.c的文件,内容如下:
#include
                                                                               
int main(void)
{
        int sub_x,sub_y,add_x,add_y;
        printf("sub_x: ");
        scanf("%d",&sub_x);
        printf("\nsub_y: ");
        scanf("%d",&sub_y);
        add_x=sub(sub_x,sub_y);
        printf("\nadd_x=sub(%d, %d)= %d",sub_x,sub_y,add_x);
        printf("\nadd_y: ");
        scanf("%d",&add_y);
        printf("\n%d",add(add_x,add_y));
}


呵呵,这些弄完后,准备开始了哦,呵呵!先说下步骤:
1> 首先运行autoscan,原因我也不知道
2> 修改configure.scan。除了要添加AM_INIT_AUTOMAKE,还要加上一行AC_PROG_LIBTOOL,这一个宏打开对Libtool的处理过程,为后面的Libtool做准备,AC_OUTPUT输出三个makefile,呵呵,AC_OUTPUT(Makefile add/Makefile sub/Makefile),最后要将configure.scan保存为configure.in
3> 运行libtoolize生成一些支持文件
4> 运行aclocal和autoscanf,还要运行autoheader,这一项是书上没有说的,但是我发现如果不运行autoheader,那么在后面的make会产生一个错误,说找不到configure.h.in
5> 在add下编写Makefile.am,内容如下:
lib_LTLIBRARIES=libadd.la
libadd_la_SOURCES=add.c
在sub下也要编写Makefile.am,内容如下:
lib_LTLIBRARIES=libsub.la
libsub_la_SOURCES=sub.c
在hello下也要编写Makefile.am,内容如下:
UTOMAKE_OPTIONS=foreign
SUBDIRS=add sub
bin_PROGRAMS=main
main_SOURCES=main.c
main_LDADD=add/libadd.la sub/libsub.la
6> 写好了Makefile.am,运行automake -a
7> 然后执行 ./configure
8> 最后make
[root@localhost root]# cd hello
[root@localhost hello]# ls
add  main.c  sub
[root@localhost hello]# autoscan   
[root@localhost hello]# ls
add  autoscan.log  configure.scan  main.c  sub
[root@localhost hello]# vim configure.in
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
                                                                               
AC_PREREQ(2.57)
AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
AM_INIT_AUTOMAKE(main,1.0)
AC_CONFIG_SRCDIR([main.c])
AC_CONFIG_HEADER([config.h])
                                                                               
# Checks for programs.
AC_PROG_CC
                                                                               
# Checks for libraries.
AC_PROG_LIBTOOL
                                                                               
# Checks for header files.
                                                                               
# Checks for typedefs, structures, and compiler characteristics.
                                                                               
# Checks for library functions.
                                                                               
AC_OUTPUT(Makefile add/Makefile sub/Makefile)

[root@localhost hello]# libtoolize
You should add the contents of `/usr/share/aclocal/libtool.m4' to `aclocal.m4'.
[root@localhost hello]# ls
add           config.guess  configure.in    ltmain.sh  sub
autoscan.log  config.sub    configure.scan  main.c
[root@localhost hello]# aclocal
[root@localhost hello]# autoconf
[root@localhost hello]# autoheader
[root@localhost hello]# ls
aclocal.m4      autoscan.log  config.sub    configure.scan  sub
add             config.guess  configure     ltmain.sh
autom4te.cache  config.h.in   configure.in  main.c
//接下来编写3个Makefile.am,这个过程我就不细说啦。
[root@localhost hello]# ls
aclocal.m4      autoscan.log  config.sub    configure.scan  Makefile.am
add             config.guess  configure     ltmain.sh       sub
autom4te.cache  config.h.in   configure.in  main.c
[root@localhost hello]# ls ./add
add.c  Makefile.am
[root@localhost hello]# ls ./sub
Makefile.am  sub.c
[root@localhost hello]# automake -a
configure.in:8: `automake requires `AM_CONFIG_HEADER', not `AC_CONFIG_HEADER'
configure.in: installing `./install-sh'
configure.in: installing `./mkinstalldirs'
configure.in: installing `./missing'
Makefile.am: installing `./INSTALL'
Makefile.am: required file `./NEWS' not found
Makefile.am: required file `./README' not found
Makefile.am: installing `./COPYING'
Makefile.am: required file `./AUTHORS' not found
Makefile.am: required file `./ChangeLog' not found
Makefile.am: installing `./depcomp'
[root@localhost hello]# ls
aclocal.m4      config.guess  configure.in    INSTALL     Makefile.am    sub
add             config.h.in   configure.scan  install-sh  Makefile.in
autom4te.cache  config.sub    COPYING         ltmain.sh   missing
autoscan.log    configure     depcomp         main.c      mkinstalldirs
//又多了几个东东
[root@localhost hello]# ./configure   //这个过程比较长
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking for C compiler default output... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking for ld used by GCC... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for /usr/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/bin/nm -B
checking for a sed that does not truncate output... /bin/sed
checking whether ln -s works... yes
checking how to recognise dependent libraries... pass_all
checking command to parse /usr/bin/nm -B output... ok
checking how to run the C preprocessor... gcc -E
checking for egrep... grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking for ranlib... ranlib
checking for strip... strip
checking for objdir... .libs
checking for gcc option to produce PIC... -fPIC
checking if gcc PIC flag -fPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.lo... yes
checking if gcc supports -fno-rtti -fno-exceptions... yes
checking whether the linker (/usr/bin/ld) supports shared libraries... yes
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking dynamic linker characteristics... GNU/Linux ld.so
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking whether -lc should be explicitly linked in... no
creating libtool
configure: creating ./config.status
config.status: creating Makefile   //看到这三个Makefile了没有,呵呵,它已经建好了
config.status: creating add/Makefile
config.status: creating sub/Makefile
config.status: creating config.h
config.status: executing depfiles commands
[root@localhost hello]# make   //这个也有点花时间
cd . && /bin/sh ./config.status config.h
config.status: creating config.h
config.status: config.h is unchanged
make  all-recursive
make[1]: Entering directory `/root/hello'
Making all in add
make[2]: Entering directory `/root/hello/add'
source='add.c' object='add.lo' libtool=yes \
depfile='.deps/add.Plo' tmpdepfile='.deps/add.TPlo' \
depmode=gcc3 /bin/sh ../depcomp \
/bin/sh ../libtool --mode=compile gcc -DHAVE_CONFIG_H -I. -I. -I..     -g -O2 -c -o add.lo `test -f 'add.c' || echo './'`add.c
rm -f .libs/add.lo
gcc -DHAVE_CONFIG_H -I. -I. -I.. -g -O2 -c add.c -MT add.lo -MD -MP -MF .deps/add.TPlo  -fPIC -DPIC -o .libs/add.lo
gcc -DHAVE_CONFIG_H -I. -I. -I.. -g -O2 -c add.c -MT add.lo -MD -MP -MF .deps/add.TPlo -o add.o >/dev/null 2>&1
mv -f .libs/add.lo add.lo
/bin/sh ../libtool --mode=link gcc  -g -O2   -o libadd.la -rpath /usr/local/lib
 add.lo
rm -fr .libs/libadd.la .libs/libadd.* .libs/libadd.*
gcc -shared  add.lo   -Wl,-soname -Wl,libadd.so.0 -o .libs/libadd.so.0.0.0
(cd .libs && rm -f libadd.so.0 && ln -s libadd.so.0.0.0 libadd.so.0)
(cd .libs && rm -f libadd.so && ln -s libadd.so.0.0.0 libadd.so)
ar cru .libs/libadd.a  add.o
ranlib .libs/libadd.a
creating libadd.la
(cd .libs && rm -f libadd.la && ln -s ../libadd.la libadd.la)
make[2]: Leaving directory `/root/hello/add'
Making all in sub
make[2]: Entering directory `/root/hello/sub'
source='sub.c' object='sub.lo' libtool=yes \
depfile='.deps/sub.Plo' tmpdepfile='.deps/sub.TPlo' \
depmode=gcc3 /bin/sh ../depcomp \
/bin/sh ../libtool --mode=compile gcc -DHAVE_CONFIG_H -I. -I. -I..     -g -O2 -c -o sub.lo `test -f 'sub.c' || echo './'`sub.c
rm -f .libs/sub.lo
gcc -DHAVE_CONFIG_H -I. -I. -I.. -g -O2 -c sub.c -MT sub.lo -MD -MP -MF .deps/sub.TPlo  -fPIC -DPIC -o .libs/sub.lo
gcc -DHAVE_CONFIG_H -I. -I. -I.. -g -O2 -c sub.c -MT sub.lo -MD -MP -MF .deps/sub.TPlo -o sub.o >/dev/null 2>&1
mv -f .libs/sub.lo sub.lo
/bin/sh ../libtool --mode=link gcc  -g -O2   -o libsub.la -rpath /usr/local/lib
 sub.lo
rm -fr .libs/libsub.la .libs/libsub.* .libs/libsub.*
gcc -shared  sub.lo   -Wl,-soname -Wl,libsub.so.0 -o .libs/libsub.so.0.0.0
(cd .libs && rm -f libsub.so.0 && ln -s libsub.so.0.0.0 libsub.so.0)
(cd .libs && rm -f libsub.so && ln -s libsub.so.0.0.0 libsub.so)
ar cru .libs/libsub.a  sub.o
ranlib .libs/libsub.a
creating libsub.la
(cd .libs && rm -f libsub.la && ln -s ../libsub.la libsub.la)
make[2]: Leaving directory `/root/hello/sub'
make[2]: Entering directory `/root/hello'
source='main.c' object='main.o' libtool=no \
depfile='.deps/main.Po' tmpdepfile='.deps/main.TPo' \
depmode=gcc3 /bin/sh ./depcomp \
gcc -DHAVE_CONFIG_H -I. -I. -I.     -g -O2 -c `test -f 'main.c' || echo './'`main.c
/bin/sh ./libtool --mode=link gcc  -g -O2   -o main  main.o add/libadd.la sub/libsub.la
mkdir .libs
gcc -g -O2 -o .libs/main main.o  add/.libs/libadd.so sub/.libs/libsub.so -Wl,--rpath -Wl,/usr/local/lib
creating main   //看到它了没有,它是可执行的文件,运行它就可以看到结果拉
cd . && /bin/sh ./config.status config.h
config.status: creating config.h
config.status: config.h is unchanged
make[2]: Leaving directory `/root/hello'
make[1]: Leaving directory `/root/hello'
[root@localhost hello]# ls
aclocal.m4      config.h.in    configure.scan  ltmain.sh    Makefile.in
add             config.log     COPYING         main         missing
autom4te.cache  config.status  depcomp         main.c       mkinstalldirs
autoscan.log    config.sub     INSTALL         main.o       sub
config.guess    configure      install-sh      Makefile
config.h        configure.in   libtool         Makefile.am
[root@localhost hello]# ./main
sub_x: 6
 
sub_y: 5
 
add_x=sub(6, 5)= 1
add_y: 4
 
5[root@localhost hello]#

呵呵,完毕!这东东要多练才能熟练。





系统分类: 嵌入式  |  用户分类: Linux学习  |  标签: 无标签  |  来源: 原创  | 

点击查看原文

发表评论 阅读全文(1821) | 回复(0)

发表于 2007/10/10 20:50:51

1

关于投票

arm-elf-gcc与arm-linux-gcc区别区[原]

    昨天晚上研究vivi时,发现head.S后面的S是个大写的,有点郁闷,于是乎网络搜索,原来.S表示需要预处理的汇编文件,小s不需要预处理的文件; 后来有看了一个牛人写的笔记,发现他也发现这问题,并做了解释,可是他这个解释是在另一篇文章里说,汗,这个小东东还要一篇文章来解释?于是乎去看看再说,发现他在讲述linux的汇编,突然一想,也是啊,linux下的针对ARM的汇编又将是什么样的呢,我看了看head.S,发现语句和ADS下的一样,只是语法有些不同,比如说@这东东在ADS里面没有的,linux下是注释,而且和linux的汇编是一样的,看来有必要研究一下arm-linux-gcc和汇编了哦; 于是今天下午去图书馆找相关书,竟然发现没有一本专门讲汇编的书,后来无意之中拿起《基于S3C44B0X嵌入式uCLinux系统原理与应用》时发现里面介绍了arm-elf-gcc以及汇编,呵呵,正是我想要的,当时一时疏忽竟然把arm-elf-gcc和arm-linux-gcc搞混了,呵呵,知道刚才才发现,呵呵遇到问题我不怕,因为我会用网络解决问题,网络搜索之,发现他们只是针对于不同的内核的编译器,请看一句话讲清楚arm-linux-gcc和arm-elf-gcc的区别,这里面讲得很直接,更详细的看http://www.shengfang.org/blog/p/20070703arm-linux-gccarm-elf-gccdiff.php。

系统分类: 嵌入式  |  用户分类: Linux学习  |  标签: 无标签  |  来源: 原创  | 

点击查看原文

发表评论 阅读全文(2519) | 回复(0)

发表于 2007/10/5 23:30:26

0

关于投票

autotools魔鬼使用[原]

呵呵!刚刚又练了一下用autotools来生成makefile,呵呵,感觉比前一次好多拉。
[root@localhost root]# mkdir -m 777 ./hello         //新建一个文件夹放源文件,其实这相当于一个项目工程文件夹
[root@localhost root]# cd hello
[root@localhost hello]# vim hello.c          //新建一个hello.c的文件,输入如下内容
#include<stdio.h>
int main(void)
{
        printf("Hello, Lammy!\n");
        return 0;
}//呵呵,简单吧
//接下来就开始使用autotools来生成Makefile
[root@localhost hello]# ls
hello.c
[root@localhost hello]# autoscan      //利用它来生成configure.in的原型文件
configure.scan
[root@localhost hello]# ls               //发现有什么不一样了没有
autoscan.log  configure.scan  hello.c
//然后修改
configure.scan,并保存为configure.in
[root@localhost hello]# vim configure.scan

#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
                                                                               
AC_PREREQ(2.57)
AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
AC_CONFIG_SRCDIR([hello.c])
AC_CONFIG_HEADER([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_OUTPUT

//把它修改为如下:
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
                                                                               
AC_PREREQ(2.57)
#AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
AC_INIT(hello,1.0)
AM_INIT_AUTOMAKE(hello,1.0)
                                                                               
AC_CONFIG_SRCDIR([hello.c])
AM_CONFIG_HEADER([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])//
AC_CONFIG_FILES用于生成Makefile的宏
AC_OUTPUT


//保存为configure.in,注意紫罗兰色部分,具体为什么可以看看http://seul.org/docs/autotut/,上面有关各个宏观的作用,不过是英文的
[root@localhost hello]# aclocal    //生成
aclocal.m4
[root@localhost hello]# autoconf   //生成
configure   
[root@localhost hello]# ls      //又多了东西
aclocal.m4      autoscan.log  configure.in    hello.c
autom4te.cache  configure     configure.scan
[root@localhost hello]# autoheader    //生成
config.h.in
[root@localhost hello]# ls
aclocal.m4      autoscan.log  configure     configure.scan
autom4te.cache  config.h.in   configure.in  hello.c
//新建一个Makefile.am,它是automake的脚本,很简单
[root@localhost hello]# vim Makefile.am
//输入如下,具体什么我就不介绍啦,记住就行

AUTOMAKE_OPTIONS=foreign

bin_PRONGRAMS =hello
hello_SOURCES =hello.c
[root@localhost hello]# automake --add-missing   //生成configure.in
configure.in: installing `./install-sh'
configure.in: installing `./mkinstalldirs'
configure.in: installing `./missing'
Makefile.am: installing `./depcomp'
[root@localhost hello]# ls
aclocal.m4      config.h.in   configure.scan  install-sh   missing
autom4te.cache  configure     depcomp         Makefile.am  mkinstalldirs
autoscan.log    configure.in  hello.c         Makefile.in

[root@localhost hello]# ./configure      //生成Makefile
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking for C compiler default output... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config.h
config.status: executing depfiles commands
[root@localhost hello]# make      //编译并生成可运行的运行文件
make  all-am
make[1]: Entering directory `/root/hello'
source='hello.c' object='hello.o' libtool=no \
depfile='.deps/hello.Po' tmpdepfile='.deps/hello.TPo' \
depmode=gcc3 /bin/sh ./depcomp \
gcc -DHAVE_CONFIG_H -I. -I. -I.     -g -O2 -c `test -f 'hello.c' || echo './'`hello.c
gcc  -g -O2   -o hello  hello.o
make[1]: Leaving directory `/root/hello'
[root@localhost hello]# ls      //看到它了没有
aclocal.m4      config.log      depcomp     Makefile       stamp-h1
autom4te.cache  config.status   hello       Makefile.am
autoscan.log    configure       hello.c     Makefile.in
config.h        configure.in    hello.o     missing
config.h.in     configure.scan  install-sh  mkinstalldirs
[root@localhost hello]# ./hello   //运行下看看
Hello, Lammy!

//可以看看Makefile发现挺大的,呵呵,不管,能用就行,另外附加几个心得:
1>如果你的源文件有问题,在 make时它会有提示的,所以
Makefile的生成和你的源文件正确与否没有联系,所以你修改了源文件时,只要文件名没有改,那么你可以直接从 make开始
2>
AC_INIT(hello,1.0)
AM_INIT_AUTOMAKE(hello,1.0)
                                                                               
AC_CONFIG_SRCDIR([hello.c])
AM_CONFIG_HEADER([config.h])//
这几个宏顺序别弄反啦哦


更具体的请看http://seul.org/docs/autotut/。

系统分类: 嵌入式  |  用户分类: Linux学习  |  标签: 无标签  |  来源: 原创  | 

点击查看原文

发表评论 阅读全文(892) | 回复(0)

发表于 2007/10/2 22:06:03

1

关于投票

gdb调试器学习[原]

    这两天一直忙着写简历,修改简历,但是始终还是出现了小问题,已经投了两份网投,哎!感觉有点悬!自己已经无法对过去进行弥补,只能继续努力,吸取教训,继续前进。
    刚刚学了下gdb调试器的简单使用,感觉还不错,趁热打铁,把过程讲述下,自己也增强下,呵呵,废话少说,Begin!!!
[root@localhost hello]# vim test.c      //新建一个test.c的源文件
在test.c中键入如下代码,很简单的程序:
/*test.c*/
#include
int sum(int m);
                                                                               
int main(void)
{
        int i,m =0;
        sum(50);
        for(i=50; i!=0; i--)m+=i;
        printf("The sum of 1~50 is %d \n",m);
}
                                                                               
int sum(int m)
{
        int i,n =0;
//      sum(50);
        for(i=m; i!=0; i--)n+=i;
        printf("The sum of 1~m is %d \n",n);
}
完了后保存它,返回终端
[root@localhost hello]# gcc -g test.c -o test         //记得一定要加 -g,这样编译出的可执行代码才包含调试的信息,否则gdb是无法载入的
[root@localhost hello]# gdb test                 //test为带有调试信息的目标文件 
GNU gdb Red Hat Linux (5.3post-0.20021129.18rh)
Copyright 2003 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 "i386-redhat-linux-gnu"...
(gdb)            //以上的信息就是gdb的启动画面,指定了gdb的版本号等信息
//然后键入 l 查看加载的文件,l表示list,b表示breakpoint,p表示print
(gdb) l         //一次加载10行总[
个人总结],
1       /*test.c*/
2       #include
3       int sum(int m);
4
5       int main(void)
6       {
7               int i,m =0;
8               sum(50);
9               for(i=50; i!=0; i--)m+=i;
10              printf("The sum of 1~50 is %d \n",m);
(gdb)
(gdb) l         //继续通过参数 l 加载,加载接下来的10行
11      }
12
13      int sum(int m)
14      {
15              int i,n =0;
16      //      sum(50);
17              for(i=m; i!=0; i--)n+=i;
18              printf("The sum of 1~m is %d \n",n);
19      }
(gdb) l         //加载完毕,再加载显然是不会在加了哈
Line number 20 out of range; test.c has 19 lines.
//首先来看怎么设断点
(gdb) b 8      //b表示设断点,后面表示行号,就是加载时显示的行号
Breakpoint 1 at 0x804833f: file test.c, line 8.
(gdb) b 9
Breakpoint 2 at 0x804834c: file test.c, line 9.
(gdb) info b   //我设了两个断点,通过info 来查看断点信息
Num Type           Disp Enb Address    What
1   breakpoint     keep y   0x0804833f in main at test.c:8
2   breakpoint     keep y   0x0804834c in main at test.c:9
(gdb)

(gdb) r      //r表示run,运行至断点1,如果没设断点,则运行至结尾
Starting program: /root/hello/test
 
Breakpoint 1, main () at test.c:8
8               sum(50);
(gdb) c      //c表示continue,继续运行
Continuing.
The sum of 1~m is 1275
 
Breakpoint 2, main () at test.c:9
9               for(i=50; i!=0; i--)m+=i;
(gdb)      //呵呵,上面几个操作看明白了吧
//怎么来看变量值呢
(gdb) l      //先用l来看看源码
4
5       int main(void)
6       {
7               int i,m =0;
8               sum(50);
9               for(i=50; i!=0; i--)m+=i;
10              printf("The sum of 1~50 is %d \n",m);
11      }
12
13      int sum(int m)
(gdb) p m   //p表示print,打印m的值
$1 = 0
(gdb) p i   //打印i的值,i为什么这么大,应该不用我介绍了吧
$2 = 1073828704
//变量知道怎么看了,那么单步运行呢
(gdb) n      //n表示单步运行,这表示一次运行一行,所以它不会进入调用的函数

10              printf("The sum of 1~50 is %d \n",m);
(gdb) n      //n的运行机制通过这俩个n应该要看出个门道来喽,我用颜色强调了下,明白了没
The sum of 1~50 is 1275
11      }
//那么如果碰到调用函数怎么进入呢,不急,有办法
(gdb) run
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /root/hello/test
 
Breakpoint 1, main () at test.c:8
8               sum(50);   //前面设的断点,表示下一步将运行这断点所在的行
(gdb) s      //用s来进入函数,也就说s也是单步运行的意思,但是它碰到函数时会进入函数运行; 而n不会,直接跳过
sum (m=50) at test.c:15   //仔细看看,是不是进入了sum函数哈
15              int i,n =0;
(gdb) s
17              for(i=m; i!=0; i--)n+=i;
(gdb) s
18              printf("The sum of 1~m is %d \n",n);
(gdb)
//这样在windows下的编译器的调试方法在gdb中都有相应的命令对应,并且更加灵活,哦忘了说怎么取消断点拉,呵呵简单
(gdb) info b      //首先查看断点信息
Num Type           Disp Enb Address    What
1   breakpoint     keep y   0x0804833f in main at test.c:8
        breakpoint already hit 1 time
2   breakpoint     keep y   0x0804834c in main at test.c:9
(gdb) delet 1      //用delet取消断点,后面的数字应该明白吧
//还有其它命令可以通过输入help来查看,或者help command[需要查看的命令]来查看
//退出gdb,返回终端是通过q来实现的
(gdb) q
The program is running.  Exit anyway? (y or n) y
[root@localhost hello]#
还有其它很多命令,我就不一一介绍拉。
     


系统分类: 嵌入式  |  用户分类: Linux学习  |  标签: 无标签  |  来源: 原创  | 

点击查看原文

发表评论 阅读全文(1090) | 回复(0)

发表于 2007/9/29 10:59:38

2

关于投票

第一个linux C程序程[原]

昨天搜了一天的网络,试图找出在linux下网络下载程序至GEC2410内,可是出现在我面前的最多的是关于Bootloader的移植,当然对这个东西有了一个入门级的了解,不想再深入下去,因为没有linux下C使用的基础,所以得从gcc开始。
呵呵,步入正题:
打开终端---->输入vim
[root@localhost root]# vim hello.c
进入vim的命令模式,按下键盘的i切换到插入模式,输入如下代码:
#include
int main()
{
        printf("Hello! This is our embeded world!\n");
        return 0;
}
按下Esc进入命令模式,输入:wq,自然会保存文件会退回到终端
接下来就是预处理、链接、编译、运行拉
[root@localhost root]# gcc -E hello.c -o hello.i      //预处理
[root@localhost root]# gcc -S hello.i -o hello.s     
//编译不汇编,生成汇编文件
[root@localhost root]# gcc -c hello.s -o hello.o     
//编译不链接。生成目标文件
[root@localhost root]# gcc hello.o -o hello         
//生成执行文件
[root@localhost root]# ./hello                      //运行执行文件
Hello! This is our embeded world!                  //这就是输出的结果

系统分类: 嵌入式  |  用户分类: Linux学习  |  标签: 无标签  |  来源: 原创  | 

点击查看原文

发表评论 阅读全文(864) | 回复(1)

发表于 2007/9/28 9:05:05

1

关于投票

如何开启VMware串口[原]

先前在玩GEC2410时,有个想法,就是在linux下进行调试,由于目标板上电或复位时会发送信息给PC机的串口,这已在windows下实现过,于 是想在linux下看看效果,可是当时我在linux下设好串口后,发现一点反应都没有,当时以为是自己没有安装交叉编译环境,于是昨天晚上把嵌入式 linux下的交叉编译环境装好后,心想这下应该可以拉,没想到我上电目标板,linux下的串口一直没有反应,郁闷,怎么这样呢,既然不适交叉编译环境 的原因,总得有个原因吧,于是我上网搜,先前我也够笨的,怎么就不知道上网查呢,呵呵,原来是我没有把VMware的串口打开,呵呵,马上关机[关虚拟机下的系统],在VM->Setting......->点击ADD,把串口加进来,呵呵设置时尽量不要用自动检测,要选中串口,反正即使你的虚拟系统启动后可以随便改的,同时要把串口设为启动时就连接拉,这样,linux下的串口在目标板上电或复位后收到和windows下一样的数据,哈哈,爽!

系统分类: 嵌入式  |  用户分类: Linux学习  |  标签: 无标签  |  来源: 原创  | 

点击查看原文

发表评论 阅读全文(3689) | 回复(2)

发表于 2007/9/27 22:36:23

1

关于投票

Linux shell学习笔记[3][原]

find    :在指定目录中搜索文件,它的使用权限是所有用户
    [root@localhost fcitx-3.4.2-bin]# find ./ -printf chmod                //-printf:搜出结果并打印
    chmodchmodchmodchmodchmodchmodchmodchmodchmodchmodchmodchmodchmodchmodchmodchmodchmodchmodchmodchmod
    chmodchmodchmodchmodchmodchmodchmodchmod
locate    :用于查找文件。其方法是先建立一个包括系统内所有文件名称及路径的数据库,之后当寻找时就只需要查询这个数据库,而不必实
    际深入档案系统之中因此其速度比find快很多。
    [root@localhost root]# locate -n 10 c                        //搜索含c的文件,并仅仅显示10行
    ./usr/bin/fcitx
    ./usr/share/fcitx
    ./usr/share/fcitx/doc
    ./usr/share/fcitx/doc/pinyin.txt
    ./usr/share/fcitx/doc/cjkvinput.txt
    ./usr/share/fcitx/doc/fcitx3.pdf
    ./usr/share/fcitx/doc/wb_fh.htm
    ./usr/share/fcitx/xpm
    ./usr/share/fcitx/data
    ./usr/share/fcitx/data/punc.mb
ln    :建立文件之间的连接,所谓的连接,它类似于windows下的快捷方式.在连接中又分为硬连接和软连接:
    硬连接:不带参数-->ln ** **;它会在用户选定的位置上生成一个和源文件大小相同的文件,属于不同的硬盘区域,所以当源文件不
    在时,目标文件依然在。
    [root@localhost root]# ls    
    fcitx3.pdf  gcc_programe  lammy  minicom.log  other  vmware-tools-distrib
    [root@localhost root]# ln lammy lammy
    ln: ‘lammy’: 不允许将硬链接连至目录
    [root@localhost root]# ln fcitx3.pdf ./lammy/fcitx3.pdf
    [root@localhost root]# ls -l ./lammy/fcitx3.pdf
    -rwxrw-rw-    2 root     root       209740  9月 27 08:26 ./lammy/fcitx3.pdf
    [root@localhost root]# rm fcitx3.pdf
    rm:是否删除一般文件‘fcitx3.pdf’? y
    [root@localhost root]# ls
    gcc_programe  lammy  minicom.log  other  vmware-tools-distrib
    [root@localhost root]# ls ./lammy
    fcitx3.pdf  Linux shell学习笔记  Linux shell学习笔记~
    软连接:带参数---->ln -s ** **;它只会在用户指定的位置生成一个文件的镜像,所以当源文件不在时,镜像文件也就不在拉。
    这个软连接的示例就不贴拉,主要是没有颜色体现,达不到那个效果。
gzip    :对文件进行压缩和解压缩,而且gzip根据文件类型可自动识别压缩或解压。
    [root@localhost other]# gzip install.log                    //只能压缩单个文件不能压缩目录
    [root@localhost other]# ls
    anaconda-ks.cfg  install.log.gz  install.log.syslog
    [root@localhost other]# gunzip install.log.gz                    //用gunzip解压缩
    [root@localhost other]# ls
    anaconda-ks.cfg  install.log  install.log.syslog
tar    :对文件目录进行打包或解包
    [root@localhost root]# ls
    gcc_programe  lammy  minicom.log  other  vmware-tools-distrib
    [root@localhost root]# tar -cvf lammy.tar ./lammy                //压缩
    ./lammy/
    ./lammy/.kde/
    ./lammy/.kde/Autostart/
    ./lammy/.kde/Autostart/Autorun.desktop
    ./lammy/.kde/Autostart/.directory
    ./lammy/.bash_logout
    ./lammy/.bash_profile
    ./lammy/.bashrc
    ./lammy/.emacs
    ./lammy/.gtkrc
    ./lammy/.bash_history
    ./lammy/Linux shell学习笔记
    ./lammy/Linux shell学习笔记~
    [root@localhost root]# ls
    gcc_programe  lammy  lammy.tar  minicom.log  other  vmware-tools-distrib
    [root@localhost root]# tar -oxvf lammy.tar                    //解压
    ./lammy/
    ./lammy/.kde/
    ./lammy/.kde/Autostart/
    ./lammy/.kde/Autostart/Autorun.desktop
    ./lammy/.kde/Autostart/.directory
    ./lammy/.bash_logout
    ./lammy/.bash_profile
    ./lammy/.bashrc
    ./lammy/.emacs
    ./lammy/.gtkrc
    ./lammy/.bash_history
    ./lammy/Linux shell学习笔记
    ./lammy/Linux shell学习笔记~

系统分类: 嵌入式  |  用户分类: Linux学习  |  标签: 无标签  |  来源: 原创  | 

点击查看原文

发表评论 阅读全文(782) | 回复(0)

2Next >Total , Page /