kk Blog —— 通用基础


date [-d @int|str] [+%s|"+%F %T"]
netstat -ltunp
sar -n DEV 1

systemtap article

https://sourceware.org/systemtap/wiki/WarStories

http://wenku.baidu.com/view/9045426048d7c1c708a1452d.html

http://www.cnblogs.com/hazir/p/systemtap_introduction.html

https://sourceware.org/systemtap/wiki/WarStories

http://www.cnblogs.com/wangkangluo1/archive/2012/06/26/2562971.html

http://www.ibm.com/developerworks/cn/linux/l-systemtap/index.html

http://blog.yufeng.info/archives/855

http://www.360doc.com/content/12/0523/15/7982302_213133871.shtml

https://sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps

http://www.docin.com/p-610001474.html

http://blog.chinaunix.net/uid-7585066-id-2048719.html

http://blog.chinaunix.net/uid-20568790-id-1632313.html

wiki翻译

http://blog.csdn.net/linyt/article/details/5204841

gcc编译安装

ftp://ftp.gnu.org/pub/gnu/gcc/gcc-4.6.2/gcc-4.6.2.tar.gz

ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-4.3.2.tar.bz2

ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-2.4.2.tar.bz2

ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-0.8.1.tar.gz

安装依赖

1
gcc configure: error: Building GCC requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0+

从错误中可以看出:GCC编译需要GMP, MPFR, MPC这三个库(有的系统已经安装了就没有这个提示,我的没有安装),有两种安装方法(建议第二种):

手动安装

我使用的版本为gmp-4.3.2,mpfr-2.4.2和mpc-0.8.1,在 ftp://gcc.gnu.org/pub/gcc/infrastructure/ 下载,根据提示的顺序分别安装GMP,MPFR和MPC(mpfr依赖gmp,mpc依赖gmp和mpfr),这里全部自己指定了安装目录,如果没有指定则默认分装在在/usr/include、/usr/lib和/usr/share,管理起来不方便,比如想卸载的时候还得一个个去找:

1
2
3
安装gmp:  ./configure --prefix=/usr/local/gmp-4.3.2; make install
安装mpfr: ./configure --prefix=/usr/local/mpfr-2.4.2 --with-gmp=/usr/local/gmp-4.3.2/; make install
安装mpc:  ./configure --prefix=/usr/local/mpc-0.8.1 --with-gmp=/usr/local/gmp-4.3.2/ --with-mpfr=/usr/local/mpfr-2.4.2/; make install

gcc自带脚本安装

gcc源码包中自带了一个gcc依赖库安装脚本download_prerequisites,位置在gcc源码目录中的contrib/download_prerequisites,因此只需要进入该目录,直接运行脚本安装即可:./download_prerequisites

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
MPFR=mpfr-2.4.2
GMP=gmp-4.3.2
MPC=mpc-0.8.1

wget ftp://gcc.gnu.org/pub/gcc/infrastructure/$MPFR.tar.bz2 || exit 1
tar xjf $MPFR.tar.bz2 || exit 1
ln -sf $MPFR mpfr || exit 1

wget ftp://gcc.gnu.org/pub/gcc/infrastructure/$GMP.tar.bz2 || exit 1
tar xjf $GMP.tar.bz2  || exit 1
ln -sf $GMP gmp || exit 1

wget ftp://gcc.gnu.org/pub/gcc/infrastructure/$MPC.tar.gz || exit 1
tar xzf $MPC.tar.gz || exit 1
ln -sf $MPC mpc || exit 1

rm $MPFR.tar.bz2 $GMP.tar.bz2 $MPC.tar.gz || exit 1

配置环境变量

我这里指定了安装位置,如果没有指定则这几个库的默认位置是/usr/local/include和/usr/local/lib,不管有没有指定GCC编译时都可能会找不到这三个库,需要确认库位置是否在环境变量LD_LIBRARY_PATH中,查看环境变量内容可以用命令

1
echo $LD_LIBRARY_PATH

设置该环境变量命令如下:

1
2
3
指定安装:export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/gmp-4.3.2/lib:/usr/local/mpfr-2.4.2/lib:/usr/local/mpc-0.8.1/lib

默认安装:export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

不指定环境变量会出错:

1
configure: error: cannot compute suffix of object files: cannot compile

2.编译gcc

1)建立一个objdir来存放目标文件 然后进入该文件夹输入
1
2
/home/wulei/sourcecode/gcc-4.6.2/configure --prefix=/usr/local/gcc-4.6.2 --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c --with-gmp=/usr/local/gmp-4.3.2/ --with-mpfr=/usr/local/mpfr-2.4.2/ --with-mpc=/usr/local/mpc-0.8.1/
最终用:../gcc-4.6.2/configure --prefix=/usr/gcc-4.6.9 --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c --with-gmp=/usr/gmp-4.3.2 --with-mpfr=/usr/mpfr-2.4.2 --with-mpc=/usr/mpc-0.8.1
2)
1
2
3
make
make check
make install
错误1
1
2
/usr/bin/ld: .libs/expat_justparse_interface.o: relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
.libs/expat_justparse_interface.o: could not read symbols: Bad value

解决

1
make CXXFLAGS=-fPIC CFLAGS=-fPIC
出现问题make的时候提示如下:
1
2
3
4
5
6
7
8
Checking for suffix of object files... configure: error: in `/home/wulei/sourcecode/gcc-4.6.2/i686-pc-linux-gnu/libgcc':
configure: error: cannot compute suffix of object files: cannot compile
See `config.log' for more details.
make[2]: *** [configure-stage1-target-libgcc] 错误 1
make[2]:正在离开目录 `/home/wulei/sourcecode/gcc-4.6.2'
make[1]: *** [stage1-bubble] 错误 2
make[1]:正在离开目录 `/home/wulei/sourcecode/gcc-4.6.2'
make: *** [all] 错误 2

于是 进入/home/wulei/sourcecode/gcc-4.6.2/i686-pc-linux-gnu/libgcc查看这个路径下的config.log
发现如下的错误提示:

1
/home/wulei/sourcecode/gcc-4.6.2/host-i686-pc-linux-gnu/gcc/cc1: error while loading shared libraries: libmpfr.so.1: cannot open shared object file: No such file or directory

原因是因为linux在make的时候没有自动寻找新加入的库所以要用命令加入

1
export LD_LIBRARY_PATH=/usr/local/mpc-0.8.1/lib:/usr/local/mpfr-2.4.2/lib:/usr/local/gmp-4.3.2/lib

Makefile:161: ../.././gcc/libgcc.mvars: No such file or directory

编译gcc时,需要注意一个原则:不要再gcc的源码中直接执行./configure、make、make install等命令,需要在源码目录下另外新建一个目录,在新建的目录中执行以上命令。

--prefix

以安装supersparrow-0.0.0为例,我们打算把他安装到目录 /usr/local/supersparrow,于是在supersparrow-0.0.0目录执行带选项的脚本

1
./configure –prefix=/usr/local/supersparrow

执行成功后再编译、安装(make,make install);安装完成将自动生成目录supersparrow,而且该软件任何的文档都被复制到这个目录。为什么要指定这个安装目录?是为了以后的维护方便,假如没有用这个选项,安装过程结束后,该软件所需的软件被复制到不同的系统目录下,很难弄清楚到底复制了那些文档、都复制到哪里去了—基本上是一塌糊涂。

用了—prefix选项的另一个好处是卸载软件或移植软件。当某个安装的软件不再需要时,只须简单的删除该安装目录,就能够把软件卸载得干干净净;移植软件只需拷贝整个目录到另外一个机器即可(相同的操作系统,不同系统用–target XXX)。

一个小选项有这么方便的作用,建议在实际工作中多多使用。