mydll.h
#ifndef _MY_DLL_H
#define _MY_DLL_H_
extern int add_range (int, int);
extern double average (int*, int);
#endif // _MY_DLL_H_
mydll.c
#include "mydll.h"
int add_range (int _sta, int _end) {
int res = 0;
if (_sta > _end)
return 0x7fffffff;
for (; _sta != _end; _sta ++) {
res += _sta;
}
return res;
}
double average (int* _arr, int _cnt) {
double res = 0.0;
int i = 0;
if (_cnt <= 0)
return (double) (~0);
for (; i < _cnt; i ++)
res += _arr [i];
return (double) (res /= _cnt);
}
test.c
#include <stdio.h>
#include "mydll.h"
int main (int argc, char* argv []) {
int res = add_range (10, 200);
printf ("%d\n", res);
return 0;
}
执行:
gcc -g -c mydll.c
gcc -shared -o mydll.dll mydll.o
gcc -g -o test test.c mydll.dll
通过.def导出dll:
gcc ./mydll.def -shared -o mydll.dll mydll.o
导出.a和.def:
gcc -shared -o mydll.dll mydll.o -Wl,–out-implib,mydll.a,–output-def,mydll.def
查看dll导出:
dumpbin /exports mydll.dll
清理:
del *.o
del *.def
del *.dll
del *.obj
del *.a
参考:
《程序员的自我修养》
MinGW gcc 编译、调用dll
937

被折叠的 条评论
为什么被折叠?



