Chinaunix首页 | 论坛 | 博客
  • 博客访问: 129506
  • 博文数量: 44
  • 博客积分: 956
  • 博客等级: 准尉
  • 技术积分: 521
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-18 12:45
文章分类
文章存档

2012年(11)

2011年(33)

分类: C/C++

2011-12-30 18:50:51

打开目录:
DIR *opendir(const char *name);
name:目录的路径和名字字符串
DIR *fdopendir(int fd);
fd:文件描述符,使用open()可以打开一个目录。
读目录:
struct dirent *readdir(DIR *dir);
该函数一次只能读取一个目录项,
返回一个指向该目录项的struct dirent的结构体,该结构体中存放了关于该目录项的信息。
struct dirent{
               ino_t          d_ino;       /* inode number */
               off_t          d_off;       /* offset to the next dirent */
               unsigned short d_reclen;    /* length of this record */
               unsigned char  d_type;      /* type of file; not supported
                                              by all file system types */
               char           d_name[256]; /* filename */
}
 
库:
静态库生成:gcc -c file.c -o file.o
         ar crs libfile.a flie.o file2.o .....
动态库生成: gcc -fPIC -c file.c -o file.o
              gcc -shared -o libfile.so file.o file2.o ....
在 libfile.a libfile.so中,只有file为库名
 
使用:
静态库:
在编译程序时,使用一下选项:
    gcc a.c -Ldir -lfile -Idir -o a.out
相关选项说明:-Ldir:指定库的路径,
              -lfile:指定的库名,
              -Idir:指定头文件的目录
动态库:
      需要将编译好的动态库文件拷贝到系统默认的库文件目录下,如/lib或/usr/lib
      或者使用其他的方法将库所在的目录加入到默认搜索目录,如设置LD_LIBRARY_PATH...
 
      在编译程序的时候,只需要指定头文件目录和库的名字,即可编译程序~
阅读(1188) | 评论(0) | 转发(0) |
0

上一篇:ssh服务

下一篇:进程基础(19)

给主人留下些什么吧!~~