C编译基础
int main(int argc,char *argv[])
argc(argument count):参数的个数;
argv(argument value):参数值
argv[0] :文件名
argv[1]:第一个参数,argv[2];第二个参数,以此类推。
编译C
1 单源程序到可执行程序
编译 连接
源文件(.c)--------->目标文件(.o)------->可执行文件
hello.c -c howdy ./howdy
gcc -o:指定编译程序输出的可执行程序名
-c:指示GCC去编译源代码,不再硬盘上留下目标文件,跳过第二步
2 多源文件到可执行文件
gcc -c src1.c src2.c ...
将n个源文件创建各自的目标文件
gcc scr1.c scr2.c ... -o scr
将N个程序编译成一个目标文件,并将他们连接到可执行程序src
3 预处理
gcc -E:指示编译程序只进行预处理操作
gcc -E hello.c -o hello.i 预处理后的代码放在不需要预处理的.i 文件中
4 生成汇编语言
gcc -S :指实编译器生成汇编代码
5 创建静态库
静态库是一些.o文件的几何,他们是由编译程序按照通常的方式生成的,将程序连接到苦衷的目标文件和将程序连接到目录中的目标文件是一样的,静态库(archive)由ar管理这些静态库
构造一个库,第一部是要编译库中的目标模块。
$gcc -c hellofirst.c hellosecond.c
建库
$ar -r libhello.a hellofirst.o hellosecond.o
编译并连接程序
$gcc twohellos.c libhello.a -o twohellos
执行
$./twohellos
6 创建共享库(.so)
共享库是目标文件的几何,对象模块的每个地址(变量应用和函数调用)都是相对地址,不是绝对地址。允许在运行程序的时候,动态加在和执行共享模块
1 编译库中的对象模块
gcc -c -fpic shellofirst.c shellosecond.c
fpic使得输出的对象模块是按照可重定位方式生成
2 构造共享库
gcc -shared shellofirst.o shellosecond.o -o hello.so
3 gcc stwohellos.c hello.so -o stwohellos
但是在执行时出现了:
./stwohellos
./stwohellos: error while loading shared libraries: hello.so: cannot open shared object file: No such file or directory
一开始我以为权限不够,可是 ls -l 显示,权限是足够的。
针对这种情况这样写
gcc
相关文档:
Delphi 与 C/C++ 数据类型对照表
Delphi数据类型C/C++
ShorInt
8位有符号整数
char
Byte
8位无符号整数
BYTE,unsigned short
SmallInt
16位有符号整数
short
Word
16位无符号整数
unsigned short
Integer,LongInt
32位有符号整数
int,long
Cardinal,LongWord/DWORD
32位无符号整数
unsigned long
Int6 ......
#include <stdio.h>
#include <string.h>
/*
* decode encd with URL, the result saved to decd.
* return point to be decoded string.
* auth: baisoo email:baisoo@msn.com
*/
char *decode( char *encd, char decd[] );
int main( int argc, char *argv[] )
{
if( argc < ......
1.1.1 格式化输入输出函数
Turbo C2.0 标准库提供了两个控制台格式化输入、 输出函数printf( ) 和
scanf(), 这两个函数可以在标准输入输出设备上以各种不同的格式读写数据。
printf()函数用来向标准输出设备(屏幕)写数据; scanf() 函数用来从标准输入
设备(键盘)上读数据。下面详细介绍这两个函数的用法。
一、pr ......