高级Linux程序设计第一章:入门
1、用GCC编译
1.1、创建源文件
(main.c) C 源文件 - main.c
#include
#include “reciprocal.hpp”
int main (int argc, char **argv)
{
int i;
i = atoi (argv[1]);
printf (“The reciprocal of %d is %g\n”, i, reciprocal (i));
return 0;
}
(reciprocal.cpp) C++ 源文件 - reciprocal.cpp
#include
#include “reciprocal.hpp”
double reciprocal (int i) {
// I should be non-zero.
assert (i != 0);
return 1.0/i;
}
(reciprocal.hpp) 头文件 - reciprocal.hpp
#ifdef __cplusplus
extern “C” {
#endif
extern double reciprocal (int i);
#ifdef __cplusplus
}
#endif
1.2、编译源文件
编译main.c:
% gcc -c main.c
编译reciprocal.cpp:
% g++ -c reciprocal.cpp
参数-I指定搜索头文件的位置。
默认情况下,GCC在当前文件夹及标准库的头文件所在的文件夹来搜索头文件。
% g++ -c -I ../include reciprocal.cpp
可以用参数-D在命令行设定宏(macro),并且可以设定宏的值
对于如下程序definemacro.c:
#include "stdio.h"
#include "stdlib.h"
int main(int argc, char** argv){
int i = 3;
#ifdef CHANGEVALUE
i = 4;
#endif
printf("i = %d\n", i);
printf("PT = %f\n", PI);
}
如果编译时命令行为gcc definemacro.c,会报‘PI’ undeclared错误。
如果编译时命令行为gcc -D PI=3.14 definemacro.c,则输出如下:
i = 3
PT = 3.140000
如果编译时命令行为gcc -D PI=3.14 -D CHANGEVALUE definemacro.c,则输出如下:
i = 4
PT = 3.140000
可以用GCC编译时优化代码.
% g++ -c -O2 reciprocal.cpp
1.3、链接对象文件
g++可以将.o对象文件链接成程序
% g++ -o reciprocal main.o reciprocal.o
如果想链接其他库文件,则用参数-I
例如欲链接库libpam.a,则用如下命令行,编译器会自动加上前缀lib和后缀.a
% g++ -o reciprocal mai
相关文档:
今天自己学习 Linux设备驱动程序 第三版 第15章 内存映射和DMA. 感觉有点吃力。主要是对内存映射很多术语和概念不是很清楚,理解起来有点费劲。
后来结合英文原版,静下心来仔细学习,才算是有了一点进展。
现在在这里做一个笔记,以备以后复习用。
低端内存和高端内存
书中的图15-1有点误导人。图中将 内核虚拟地址 和 ......
以前Godaddy的Linux的主机是不能开通SSH的,只有VDS、VPS、独立主机可以开通,前几天在后台上看到有了SSH这个功能,不过需要删除所有的数据库,才可以进行开通的步骤。强烈建议备份数据库及网站!!
删除数据库就不用说了~很简单。
步骤:进入空间管理面板,选择Settings选项卡下的SSH选项,如下图:
godaddyssh-thumb. ......
在linux下一直被无法一下删除很多文件(超过1024)的问题困扰;今天找了一下,发现有一个很简单的解决办法。在terminal中输入
flora03:/scratch/weibinli> find . -name 'Rubidium*' | xargs rm
该命令一下子 将所有以Rubidium开头的文件删除掉。以此类推,应该可以将rm改为cp一次copy大数目的文件。
......
/*
* /*
* Linux x86 Dropbear SSH <= 0.34 remote root exploit
* coded by live
*
* You'll need a hacked ssh client to try this out. I included a patch
* to openssh-3.6.p1 somewhere below this comment.
*
* The point is: the buffer being exploited is too small(25 bytes) to hold our
......