php网站开发教程培训,首页定制,电子商务是坑人专业吗,网址注册在哪里注册编写 xx.c 和xx.h文件\将源代码编译为目标文件 gcc -c add.c sub.c 执行完毕后会生产add.o和sub.o文件静态库创建使用ar命令#xff1b; ar -r libmymath.a add.o sub.o将库和main.c文件一起编译 gcc -o main main.c -lmymath -L./
注意 上述书写格式不要错乱 -L 是指定文件路…编写 xx.c 和xx.h文件\将源代码编译为目标文件 gcc -c add.c sub.c 执行完毕后会生产add.o和sub.o文件静态库创建使用ar命令 ar -r libmymath.a add.o sub.o将库和main.c文件一起编译 gcc -o main main.c -lmymath -L./
注意 上述书写格式不要错乱 -L 是指定文件路径
#includeadd.h
int add(int a,int b)
{return ab;
}
//add.h
#ifndef C_ADD_H
#define C_ADD_H
int add(int a,int b);
#endif//sub.c
#includestdio.h
int sub(int a,int b)
{return a-b;
}//sub.h
#includestdio.h
int sub(int a,int b)
{return a-b;
}//main
#includestdio.h
#includeadd.h
#includesub.hint main()
{int a20,b10;int c;c add(a,b);printf(%d\n,c);return 0;
}动态库制作
动态库对应的源文件 “test_lib.c”动态库对应的头文件 “test_lib.h”
gcc test_lib.c -fPIC -shared -o libtest.so说明 -fPIC 表示生成位置无关代码PICPosition Independent Code-shared 表示创建生成动态共享库gcc test_bin1.c -L. -ltest -o test1说明编译的时候指定了libtest.so上述编译好的动态库
//test_lib.c
#include stdio.hvoid test_print(void) {printf( This is a test line.\n);return;
}//test_lib.h
#ifndef __TEST_H
#define __TEST_H
void test_print(void);
#endif