log: Starter course

来源:互联网 发布:高压电棍专卖淘宝 编辑:程序博客网 时间:2024/04/30 05:33

忠告:这篇日志是我个人开发过程中所经历程序的日志文档,包括环境配置、主要开发步骤和遇到的一些问题及解决办法。信息比较繁杂,可能并没有您想要的信息,或者不够完整和系统,请谨慎花费时间阅读:) 

如果有您感兴趣的专题,可以留言或邮件告诉我,我会有针对性地在今后整理完整的报告分享。

文中用全角括号“()”表示注释或转义

1.背景简介

在X64-Ubuntu上进行基于ARM architecture的OpenGL、OpenGL ES开发,可移植到ARM嵌入式平台中应用

2.基本环境配置

OS: Ubuntu 12.04
Win7 installed in the VMWare(对主线开发不必要,纯属使用一些windows软件辅助的需要)

版本控制软件:Subversion/git

$ sudo apt-get install subversion

$ sudo apt-get install git

有一些推荐的package也可以视需要安装一下,比如gitk(git图形界面), git-doc(xml文档), git-svn等

除了通过apt-get安装package,也可以直接下载tar压缩包进行安装(tar打包和解压的命令可以参考linux下的tar打包命令示例和详解)

$ tar xvzf package.tar.gz

$ cd package

$ ./config

$ make

$ make install

$ make clean

安装编译环境

$ sudo apt-get install build-essential

3.环境初始化

3.1 OpenGL

mesa(可以在linux下运行OpenGL ES application的仿真环境)

$ sudo apt-get install mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev freeglut3-dev

另外需要配置OpenGL ES(Embedded System,以下简称GLES)环境

这里使用的GLES版本是2.0,主要的package是libgles2-mesa-dev,这个package依赖于libegl1-mesa-dev包,而libegl1-mesa-dev包又依赖于libegl1-mesa-drivers

$ sudo apt-get install libegl1-mesa-drivers libegl1-mesa-dev libgles2-mesa-dev

当然如果你要使用GLES 1.1或更低的话,可以安装

3.2 ARM模拟环境

ARM toolchain

load环境

export DEPOT_EMULATED_PLATFORM=rhe5-amd64
. /tools/setup/init/bash
module load swdev
module load gnu/make/3.81
module load gnu/gcc/4.6.2(在ubuntu12.04中4.6.2不兼容,无需这一步)
module load codesourcery/linuxeabi/arm-2011q1
(可以将以上这些设置放在 .bashrc)

然后开始build,在此前,先将源码checkout到本地

Build X11 driver

cd trunk
VARIANT="mali400-gles11-gles20-linux-x11-no_monolithic-no_profiling-ump-max_pp_split_count_4-rgb_is_xrgb" CONFIG=debug TARGET_PLATFORM=odroidq TARGET_TOOLCHAIN=arm-linux-gcc-vfp make suites -j4
VARIANT选项列表

Build X11 kernel

cp 已经mount的kernel所在目录 本地某目录work/(选择版本kernel 3.0.15)
cd work/kernel/
make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- clean
make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi-

4. Setup Android环境

GCC编译一个例程:

$ gcc eglut.c eglut_x11.c eglutint.h dice_es1.c -o dice_es_v1 -l GLESv1_CM -l EGL(需要search /bin/include/glut,GL,GLU)

gcc使用教程可以参考:GCC Wiki,GCC and Make

gdb使用教程可以参考:GDB Tutorial


log

2013-5-6

{

vim c语言风格的高亮和缩进

在/etc/vim/下找到vimrc,这是系统公共配置文件,而每个用户也可以在自己的主目录下建立私有配置文件,命名为“.vimrc”

1)设置(软)制表符宽度为4:
set tabstop=4
set softtabstop=4
2)设置缩进的空格数为4
set shiftwidth=4
3)设置自动缩进:即每行的缩进值与上一行相等;使用 noautoindent 取消设置:
set autoindent
4)设置使用 C/C++ 语言的自动缩进方式:
set cindent
5)设置C/C++语言的具体缩进方式(以我的windows风格为例):
set cinoptions={0,1s,t0,n-2,p2s,(03s,=.5s,>1s,=1s,:1s
6)如果想在左侧显示文本的行号,可以用以下语句:
set nu
7)最后,如果没有下列语句,就加上吧:
if &term=="xterm"
set t_Co=8
set t_Sb=^[[4%dm
set t_Sf=^[[3%dm
endif
还有中文显示问题,
可以添加:
let &termencoding=&encoding
set fileencodings=utf-8,gbk,ucs-bom,cp936

}

2013-5-13

{

今天在build kernel时遇到一个ubuntu下的常见出错

mkdir: cannot create directory `xxxxxx` : File name too long

这是由于文档在home目录下build,而home目录已被eCryptsfs加密导致目录路径过长。

Ubuntu在安装时有一个选项,询问用户是否要加密用户文件夹,这里用到的就是eCryptsfs企业级加密文件系统

以下是文件名过长的原因:

eCryptfs can only store filenames of up to 143 characters when filename encryption is enabled. The remaining 112 characters are used for storing metadata such as the encrypted filename prefix, the signature of the filename encryption key, and an identifier for the cipher used, as well as random bytes to make /foo/file and /bar/file encrypt to different ciphertext and padding bytes to achieve proper cipher block size alignment.

}

2013-5-14

{

Ubuntu下安装中文输入法

}

2013-6-3

{

查看环境(系统、硬件、平台)版本信息

#cat  /etc/issue(查看操作系统版本号)

Ubuntu 12.04.2 LTS \n \l

#lsb_release -a

No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 12.04.2 LTS
Release: 12.04
Codename: precise

#cat /etc/lsb-release

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04
DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION="Ubuntu 12.04.2 LTS"

#cat /proc/version

Linux version 3.5.0-27-generic (buildd@allspice) (gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) ) #46~precise1-Ubuntu SMP Tue Mar 26 19:33:21 UTC 2013

#uname -a

Linux texom 3.5.0-27-generic #46~precise1-Ubuntu SMP Tue Mar 26 19:33:21 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

其中

kernel name(uname -s, --kernel-name)
Linux
nodename(uname -n, --nodename)
texom
kernel release(-r, --kernel-release)
3.5.0-27-generic
kernel version(-v, --kernel-version)
#46~precise1-Ubuntu  SMP Tue Mar 26 19:33:21 UTC 2013
machine hardware name(-m, --machine)
x86_64
Processor type(-p, --processor)
x86_64
hardware platform(-i, --hardware-platform)
x86_64
operating system(-o, --operating-system)
GNU/Linux

}

2013-6-4

{

  1 # tty6 - getty
  2 #
  3 # This service maintains a getty on tty6 from the point the system is
  4 # started until it is shut down again.
  5 
  6 start on runlevel [23]
  7 stop on runlevel [!23]
  8 
  9 respawn
 10 exec /sbin/getty -8 -L 115200 s3c2410_serial1

}

2013-6-5

{

linux文件查找指令

whereis <程序名称>
查找软件的安装路径
-b 只查找二进制文件
-m 只查找帮助文件
-s 只查找源代码
-u 排除指定类型文件
-f 只显示文件名
-B <目录> 在指定目录下查找二进制文件
-M <目录> 在指定目录下查找帮助文件
-S <目录> 在指定目录下查找源代码

locate <文件名称>
在文件索引数据库中搜索文件
-d <数据库路径> 搜索指定数据库
updatedb
更新文件索引数据库

find [路径] <表达式>
查找文件
-name <表达式> 根据文件名查找文件
-iname <表达式> 根据文件名查找文件,忽略大小写
-path <表达式> 根据路径查找文件
-ipath <表达式> 根据路径查找文件,忽略大小写
-amin <分钟> 过去N分钟内访问过的文件
-atime <天数> 过去N天内访问过的文件
-cmin <分钟> 过去N分钟内修改过的文件
-ctime <天数> 过去N天内修改过的文件
-anewer <参照文件> 比参照文件更晚被读取过的文件
-cnewer <参照文件> 比参照文件更晚被修改过的文件
-size <大小> 根据文件大小查找文件,单位b c w k M G
-type <文件类型> 根据文件类型查找文件。b 块设备 c 字符设备 d 目录 p 管道文件 f 普通文件 l 链接 s 端口文件
-user <用户名> 按归属用户查找文件
-uid <uid> 按UID查找文件
-group <群组名> 按归属群组查找文件
-gid <gid> 按GID查找文件
-empty 查找空文件

从文件内容查找匹配指定字符串的行:
$ grep "被查找的字符串" 文件名
从文件内容查找与正则表达式匹配的行:
$ grep –e “正则表达式” 文件名
查找时不区分大小写:
$ grep –i "被查找的字符串" 文件名
查找匹配的行数:
$ grep -c "被查找的字符串" 文件名
从文件内容查找不匹配指定字符串的行:
$ grep –v "被查找的字符串" 文件名

从根目录开始查找所有扩展名为.log的文本文件,并找出包含”ERROR”的行
find / -type f -name "*.log" | xargs grep "ERROR"

系统查找到httpd.conf文件后即时在屏幕上显示httpd.conf文件信息。 
find/-name"httpd.conf"-ls

在根目录下查找某个文件
find . -name "test"

在某个目录下查找包含某个字符串的文件

grep -r "zh_CN" ./

vim查找设置

f向前搜索并将光标停留在目标字符上F向后搜索并将光标停留在目标字符上;重复刚才的查找,反向重复刚才的查找t向前搜索并将光标停留在目标字符的前一个字符上T向后搜索并将光标停留在目标字符的后一个字符上/向前查找?向后查找n继续查找N反向查找*向前查找与当前光标下字符精确匹配的字符串#向后查找与当前光标下字符精确匹配的字符串:set hlsearch打开高亮显示查找的文本:set nohlsearch关闭高亮显示查找的文本:nohlsearch关闭当前高亮显示的结果:set incsearch打开显示查找匹配过程:set noincsearch关闭显示查找匹配过程:set ignorecase忽略大小写:set noignorecase精确匹配大小写:set nowrapscan禁止循环查找方式:set wrapscan启用循环查找方式

}

2013-6-6

{

如果需要开机自动配置环境

export DEPOT_EMULATED_PLATFORM=rhe5-amd64
load一些module

可以把指令写进脚本.bashrc。一般在用户文件目录中~/.bashrc影响到的是当前目录当前用户的环境,如果在其他用户目录中,则可以通过source指令执行即可:

source ~/.bashrc


sudo apt-get install zlib-bin

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/lib/x86_64-linux-gnu/


安装java jdk

官网上下载了jdk的bin自解压文件,把bin文件放到想安装java的目标文件中运行,得到一个目录。

然后有两种方法,一种是修改环境变量,一种是在/usr/bin中修改软连接。我使用的是第二种。

比如我将jdk安装到了/etc/java-jdk/,则:

cd /usr/bin
sudo ln -sf /etc/java-jdk/jdk1.6.0_43/bin/java java
sudo ln -sf /etc/java-jdk/jdk1.6.0_43/bin/javac javac
sudo ln -sf /etc/java-jdk/jdk1.6.0_43/bin/javadoc javadoc
sudo ln -sf /etc/java-jdk/jdk1.6.0_43/bin/javah javah  
sudo ln -sf /etc/java-jdk/jdk1.6.0_43/bin/javap javap
sudo ln -sf /etc/java-jdk/jdk1.6.0_43/bin/javaws javaws

}

2013-6-8

{

找不到crt1.o, crti.o的问题:

/usr/bin/ld: cannot find crt1.o: No such file or directory
/usr/bin/ld: cannot find crti.o: No such file or directory
collect2: ld 返回 1

原因是gcc等编译工具默认库查找目录是/usr/lib,而我们之前64位系统补装32位库是在gcc安装之后,因此产生了新的库目录/usr/lib/x86_64-linux-gnu和/usr/lib/i386-linux-gnu,不在默认查找目录中。

两种解决方法

一种是重装编译环境

sudo apt-get update
sudo apt-get install --reinstall binutils
sudo apt-get install --reinstall build-essential
sudo apt-get install --reinstall libc6-dev
sudo apt-get install --reinstall gcc-4.6
sudo apt-get install --reinstall libboost1.46-all-dev

另一种则是走了个捷径,设置环境变量

LIBRARY_PATH=/usr/lib/x86_64-linux-gnu

可以参考这篇文章

[Linux]Ubuntu的ld不搜索/usr/lib/x86_64-linux-gnu的问题 Ervin's Blog

}

2013-6-28

{

find命令结果作为参数的正则表达式

# find . -type f -exec ls -l {} \;

-exec后面接命令,再以{}空格\和分号;结尾

sudo find . -maxdepth 1 -user 14835 -exec chown -R hongyugao {} \;

find . -maxdepth 1 -group 14835 -exec mv {} ./Android-4.2 \;

}

2013-7-2

{

Linux下查看磁盘剩余空间和文件夹大小

}

2013-7-22

{

dd是Linux/UNIX 下的一个非常有用的命令,作用是用指定大小的块拷贝一个文件,并在拷贝的同时进行指定的转换。
参数
1. if=文件名:输入文件名,缺省为标准输入。即指定源文件。< if=input file >
2. of=文件名:输出文件名,缺省为标准输出。即指定目的文件。< of=output file >
3. ibs=bytes:一次读入bytes个字节,即指定一个块大小为bytes个字节。
obs=bytes:一次输出bytes个字节,即指定一个块大小为bytes个字节。
bs=bytes:同时设置读入/输出的块大小为bytes个字节。
4. cbs=bytes:一次转换bytes个字节,即指定转换缓冲区大小。
5. skip=blocks:从输入文件开头跳过blocks个块后再开始复制。
6. seek=blocks:从输出文件开头跳过blocks个块后再开始复制。
注意:通常只用当输出文件是磁盘或磁带时才有效,即备份到磁盘或磁带时才有效。
7. count=blocks:仅拷贝blocks个块,块大小等于ibs指定的字节数。
8. conv=conversion:用指定的参数转换文件。
ascii:转换ebcdic为ascii
ebcdic:转换ascii为ebcdic
ibm:转换ascii为alternate ebcdic
block:把每一行转换为长度为cbs,不足部分用空格填充
unblock:使每一行的长度都为cbs,不足部分用空格填充
lcase:把大写字符转换为小写字符
ucase:把小写字符转换为大写字符
swab:交换输入的每对字节
noerror:出错时不停止
notrunc:不截短输出文件
sync:将每个输入块填充到ibs个字节,不足部分用空(NUL)字符补齐。

}

2013-8-22

{

xf86DrvMsg的用法,Xorg如何输出日志

C99

#define LOG(format, ...) fprintf(stdout, format, __VA_ARGS__)

GCC

#define LOG(format, args...) fprintf(stdout, format, args)

可变参数的宏定义

C语言 ##__VA_ARGS__宏

}

2013-8-23

{

NFS mount 可以在/etc/fstab中编辑,使得开机自动mount

}

2013-10-29

{

字符串转换

Linux内核中提供的一些字符串转换函数:
lib/vsprintf.c

[cpp] view plaincopyprint?
  1. unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base)  
  2. unsigned long simple_strtoul(const char *cp, char **endp, unsigned int base)  
  3. long simple_strtol(const char *cp, char **endp, unsigned int base)  
  4. long long simple_strtoll(const char *cp, char **endp, unsigned int base)  
  5. int strict_strtoul(const char *cp, unsigned int base, unsigned long *res)  
  6. int strict_strtol(const char *cp, unsigned int base, long *res)  
  7. int strict_strtoull(const char *cp, unsigned int base, unsigned long long *res)  
  8. int strict_strtoll(const char *cp, unsigned int base, long long *res)  
  9. int sprintf(char *buf, const char *fmt, ...)  
  10. int snprintf(char *buf, size_t size, const char *fmt, ...)  
  11. int sscanf(const char *buf, const char *fmt, ...) 

}

2013-11-29

{

为android交叉编译Busybox

Busybox

}

2013-12-2

{

ALOGI在android系统中打印信息到log

}

2013-12-5

{

编译代码时大家不愿看到的是error, 而warning就不会那么在意. 然而,在有些情况下,warning可能意味着潜在的bug. 如果完全忽略, 就可能失去一次找到bug的机会. 很多人深有体会, 如果一个bug是逻辑上的, 通过人工排查就像是大海捞针. 因此, warning的信息可以被利用起来, 给debug带来帮助.

gcc提供了许多warning选项, 供人定制需求. 在这里可以看到所有的Options to Request or Suppress Warnings 

我最近用到的一个是

-Wunused-parameter

用来warning函数参数未使用的情形.


如果打开了这个选项,而你恰好有一段代码是有意unused,不想因此而产生一个warning,对于使用ARM toolchain的朋友来说,可以使用变量属性:__attribute__((unused))

Note

此变量属性是 ARM 编译器支持的 GNU 编译器扩展。

示例

void Variable_Attributes_unused_0(){    static int aStatic =0;    int aUnused __attribute__ ((unused));    int bUnused;    aStatic++;}

在此示例中,编译器发出已声明但从未引用 bUnused 的警告,但不会发出有关 aUnused 的警告。

Note

GNU 编译器不会生成任何警告。

}

2013-12-15

{

netcfg eth1 dhcp

setprop net.dns1 10.164.2.18

}

2013-12-16

{

头文件搜索路径

#include ".h"

①先搜索当前目录
②然后搜索-I指定的目录
③再搜索gcc的环境变量CPLUS_INCLUDE_PATH(C程序使用的是C_INCLUDE_PATH)
④最后搜索gcc的内定目录
/usr/include
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu(i686-linux-gnu)/#version#/include

#include <.h>

①先搜索-I指定的目录
②然后搜索gcc的环境变量CPLUS_INCLUDE_PATH
③最后搜索gcc的内定目录
/usr/include
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu(i686-linux-gnu)/#version#/include

库文件搜索路径

①gcc会去找-L
②再找gcc的环境变量LIBRARY_PATH
③再找内定目录 /lib /usr/lib /usr/local/lib 这是当初compile gcc时写在程序内的

运行时动态库的搜索路径

①编译目标代码时指定的动态库搜索路径(这是通过gcc 的参数"-Wl,-rpath,"指定。当指定多个动态库搜索路径时,路径之间用冒号":"分隔)
②环境变量LD_LIBRARY_PATH指定的动态库搜索路径(当通过该环境变量指定多个动态库搜索路径时,路径之间用冒号":"分隔)
③配置文件/etc/ld.so.conf中指定的动态库搜索路径;
④默认的动态库搜索路径/lib;
⑤默认的动态库搜索路径/usr/lib

参考:环境变量,include搜索路径,lib库搜索路径

}

2013-12-17

{

ubuntu文件浏览器ctrl+H查看隐藏文件

}

2013-12-24

{

LInux kernel header files package

linux-headers-$(uname -r)

我的在这

/usr/src/linux-headers-3.5.0-27-generic/include/linux

+

vfp

Virtual Floating Point

}

2014-1-7

{

-lX11 -lXfixes -ldrm -lXext -lxcb -lXau -lXdmcp

+

gdb调试带参数的程序

1.

bin arg1 arg2

gdb bin

(gdb) run arg1 arg2

2.

gdb --args ./bin arg1 arg2

}

2014-1-10

{

X11 Glossary
DDX
: Device Dependent X. The part of X that interacts with the hardware. There have been many of these over the years:xfree86, kdrive, xwin (for Windows), darwin (for OS X), xgl, vfb, xnest, and so forth. In the X server code, each directory under hw corresponds to one DDX. One DDX may have one or more device drivers. In the xfree86 DDX, each driver is a separate loadable module; in most of the other DDXes, each driver is compiled to its own server binary. Contrast: DIX.
DIX: Device Independent X. The part of X that interacts with clients and implements software rendering. Basically everything in the server except for the hw/ directory. The event delivery is part of the DIX.
DMX: Distributed Multihead X, which allows combining several backend X servers into a single virtual X server.
DRI: Direct Rendering Infrastructure. A way for X clients to send commands directly to the graphics card. Primarily used to make GLX go fast, but also involved in accelerating XvMC. All the open drivers, and many of the closed drivers, use the DRI to accelerate GLX.
EGL: Embedded-System Graphics Library. The interface between rendering APIs such as OpenGL ES and the underlying native platform window system, such as X.
EXA: Acceleration architecture with no well-defined acronym. Based on the kdrive acceleration architecture (KAA) but with some additional features and cleanups, and designed to be used within the xfree86 DDX.
git master: A term to refer to the master branch in the X server's git repository (see http://cgit.freedesktop.org). The master branch is the default when you get the X server sources, and it is where most of the development happens.
GLX: OpenGL extension for X. Provides a way to do OpenGL drawing into a window managed by the X server. Almost always available in software. The open drivers use the DRI to accelerate GLX.
KAA: kdrive acceleration architecture. Used in the kdrive DDX to accelerate core X drawing and Render. Much simpler than XAA, but with fewer restrictions on the use of offscreen memory, which is important for effectively accelerating Render.
MI: machine independent. Routines that should run on pretty much any hardware
OpenGL (ES): Open Graphics Library (Embedded Systems). The standard cross-platform API for 2D and 3D rendering. OpenGL needs a binding layer to the window system to actually display anything; relevant ones to X are GLX and EGL.
Render: An extension to the X protocol that exposes the Porter-Duff image compositing model. Unlike the core X drawing requests, the Render extension is capable of doing alpha blending. Primarily used right now to implement antialiased fonts, but is also used by the xcompmgr demo to implement drop shadows and translucency.
XAA: XFree86 Acceleration Architecture. Used in the xfree86 DDX to accelerate core X drawing requests and Render. Not really suitable for modern desktop usage anymore. Intended to be replaced by EXA in the xfree86 DDX, or by the XGL DDX.
XGL: X on OpenGL. A DDX that uses an OpenGL stack to do its rendering. The XGL DDX has several drivers: Xglx to display on a GLX surface, a la Xnest; Xegl, to display an native EGL screen; and potentially also Xwgl and Xagl to display on win32 and OSX windows. Xgl was removed from git master on the 12 June 2008 after having been orphaned for years.

}

2014-2-10

{

WARNING: The following packages cannot be authenticated!
  libc-ares2 libecore1 libecore-con1 libeet1 libevas1 libecore-input1 libecore-fb1 libecore-ipc1 libecore-x1 libecore-evas1 libecore-file1
  libecore-imf1 libedbus1 libembryo1 libedje1 libefreet1 e17-data libevas1-engines-core libevas1-engines-x libembryo-bin libedje-bin e17

apt-get install libecore-dev libevas-dev

The following package was automatically installed and is no longer required:
  libcaca-dev
Use 'apt-get autoremove' to remove it.
The following extra packages will be installed:
  comerr-dev krb5-multidev libc-ares-dev libcurl3-gnutls libcurl4-gnutls-dev libeet-dev libeet-doc libeina-dev libgssrpc4 libidn11-dev
  libkadm5clnt-mit8 libkadm5srv-mit8 libkdb5-6 libkrb5-dev libldap2-dev librtmp-dev
Suggested packages:
  krb5-doc libcurl3-dbg libecore-doc libevas-doc krb5-user
The following NEW packages will be installed:
  comerr-dev krb5-multidev libc-ares-dev libcurl4-gnutls-dev libecore-dev libeet-dev libeet-doc libeina-dev libevas-dev libgssrpc4 libidn11-dev
  libkadm5clnt-mit8 libkadm5srv-mit8 libkdb5-6 libkrb5-dev libldap2-dev librtmp-dev
The following packages will be upgraded:
  libcurl3-gnutls
1 upgraded, 17 newly installed, 0 to remove and 293 not upgraded.

}

原创粉丝点击