Linux下gcc,g++,gdb,scon部分用法笔记

时间:2023-03-09 07:33:27
Linux下gcc,g++,gdb,scon部分用法笔记

1 Ubuntu下编译安装GCC-4.1.2

  • 拷贝gcc-4.1.2.tar.bz2(我下载的压缩文件)到/usr/local/src
  • 解压

新生成的gcc-4.1.2这个目录被称为源目录,用${srcdir}表示它。目标目录(用${objdir}表示)是用来存放编译结果的地方

  • 配置shell> ${srcdir}/configure --prefix=${destdir} [其它选项]

例如,如果想将GCC 4.1.2安装到/usr/local/gcc-4.1.2目录下,则${destdir}就表示这个路径。

root@w-ProLiant-ML350-Gen9:/usr/local/gcc-4.1.2# chmod a+x ../src/gcc-4.1.2/configure
root@w-ProLiant-ML350-Gen9:/usr/local/gcc-4.1.2# ../src/gcc-4.1.2/configure --prefix=/usr/local/gcc-4.1.2 --enable-threads=posix --disable-checking --enable--long-long --host=w-ProLiant-ML350-Gen9 --with-system-zlib --enable-languages=c,c++,java
root@w-ProLiant-ML350-Gen9:/usr/local/gcc-4.1.2# make
root@w-ProLiant-ML350-Gen9:/usr/local/gcc-4.1.2# make install

2 g++编译中参数-l-L含义

The "-l" tell the compiler to look for a library and the "-L" tells it where to do the search (which is what you are probably missing).

# 定位library的位置
shell> locate cutil_x86_64
/home/cho/NVIDIA_GPU_Computing_SDK/C/lib/libcutil_x86_64.a
# eg
shell> g++ -o application main.cpp -L/home/cho/NVIDIA_GPU_Computing_SDK/C/lib -lcutil

3 gdb设置和管理断点

  • setting breakpoint
    • 以条件表达式设置断点:break 7 if i==99
  • setting temporary breakpoint
    • tb line-number
  • 删除断点

clear : 删除程序中所有的断点

clear 行号 : 删除这行的断点

clear 函数名 : 删除该函数的断点

delete b_id1 b_id2 ... : 删除指定编号的断点

4 scons简单例子

SCons是一个开放源代码、以 Python 语言编写的下一代的程序建造工具。

# simple case of hello.c:
shell> ls
hello.c SConstruct
shell> cat SConstruct
Program('hello.c') shell> scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
gcc -o hello.o -c hello.c
gcc -o hello hello.o
scons: done building targets. shell> ls
hello hello.c hello.o SConstruct
  • 编译之后清除(-c或--clean): scons -c
  • 使Scons输出更简洁: scons -Q
  • 指定目标文件的名字: Program('new_filename','filename.c')
  • 编译多个源文件: Program(['prog.c','file1.c','file2.c'])
  • 关键字参数:
src_files=Split('main.c  file1.c  file2.c')
Program(target='program', source=src_files)