windows下用GCC编译DLL

此程序有3个文件,分别为 export.h 、export.c 、main.c

 

export.h 文件内容

/*此头很有必要,别人在调用的时候知道有哪些方法*/
#ifdef BUILD_DLL
#define EXPORT __declspec(dllexport)
#else
#define EXPORT __declspec(dllimport)
#endif
EXPORT void export(void);

 

export.c 文件内容

#include<stdio.h>
#include "export.h"
EXPORT void export(void)
{
	printf("HELLO DLL\n");
}

main.c 文件内容(如果仅编译DLL文件,不需要此文件参与)

#include "export.h"
int main()
{
	export();
	return 0;
}

 

编译生成DLL

D:\>gcc -shared -o export.dll export.c

至此DLL已编译完成,其他程序可调用。

现在编译 main.c 调用此DLL

D:\>gcc -o main.exe main.c -L./ -lexport

执行 main.exe

D:\>main.exe

HELLO DLL

posted on 2015-10-29 15:24  小人物大梦想  阅读(8509)  评论(0编辑  收藏  举报

导航