基于redhat64位操作系统编写C程序和动态库
来源:互联网 发布:hope软件下载 编辑:程序博客网 时间:2024/05/21 22:23
工具:
- gedit Text Editor
下载吧
操作系统:red hat 6.4X64
示例代码
hello1.c
#include <stdio.h>int hello1(const char *str){ printf("hello word%d",1); return 1;}
hello2.c
#include <stdio.h>int hello2(char *str){ printf("hello word2");}
main.c
#include "hello1.h"#include "hello2.h"int main(){ hello1("hello1"); hello2("hello2"); return 1;}
现在对以上三个文件进行编译
生成应用程序
同时编译
gcc -c hello1.c hello2.c main.c
生成可执行文件
gcc main.o hello1.o hello2.o -o main
对于cpp文件命令:
g++ main.o hello1.o hello2.o -o main
执行可执行文件 ./main
生成动态库
动态库变译和普通的可执行文件的变译不一致,需要添加-fPIC参数
编译
gcc -fPIC -c hello1.c hello2.c
“PIC”命令行标记告诉GCC产生的代码不要包含对函数和变量具体内存位置的引用
生成动态库
gcc -shared -o libmyhello.so hello1.o hello2.o
通过mian.c调用动态库进行测试
gcc -o mainsoft main.c -L. -lmyhello2
mainsoft:生成的应用名称
-L :用于连接动态库 libmyhello.so ,标记告诉GCC函数库可能位于当前目录
执行应用:./miansoft
第一次写博客,请大家多多关照,如果有什么错误,希望大家能指出来
0 0
- 基于redhat64位操作系统编写C程序和动态库
- 32位和64位操作系统下C程序中的类型长度小结
- Visual Studio 2010下基于32位操作系统和64位操作系统的SDL配置步骤
- 多操作系统环境下编写C程序(初探)
- C语言编写基于TCP和UDP协议的Socket通信程序示例
- c语言静态库和动态库的编写
- C和C++编写、调用动态链接库的方法
- C语言中使用位运算编写程序
- 32位操作系统和64位操作系统
- C/C++32位程序移植到64位操作系统(转)
- 基于Mysql C Api编写mysql客户端程序
- 使用C/C++语言编写基于DSP程序的注意事项
- 基于Mysql C Api编写mysql客户端程序 多线程
- Linux操作系统下动态库的编写与调用
- Linux操作系统下动态库的编写与调用
- Linux操作系统下动态库的编写与调用
- Linux操作系统下动态库的编写与调用
- Linux操作系统下动态库的编写与调用
- linux iptables 配置 linux开启允许外网访问的端口
- bootstrap入门
- C语言生成MD5校验码
- rails view层的具体细节(四)
- 关于协方差矩阵的理解
- 基于redhat64位操作系统编写C程序和动态库
- 我
- DrawText英文自动换行的处理方法
- java 日期 工具类
- LeetCode - 4Sum
- Posts Tagged 【String】 Text Justification
- rails view层的具体细节(五)
- 单片机和嵌入式的一些学习心得
- 基于ARM 构架(带MMU)的copy_from_user与copy_to_user详细分析