简单创建hello.c,hello.h,和main.c调用。
hello.h:
#ifndef HELLO_H
#define HELLO_H
#include<stdio.h>
__declspec(dllexport) void hello();
#endif
hello.c:
#include "hello.h"
void hello()
{
printf("hello\n");
}
编译为dll:
clang hello.c -shared -o hello.dll
生成三个文件:
.lib为动态lib文件,相当于.h,这个是window才有的吧,和linux不一样。
使用:
main.c:
#include "hello.h"
//例子
int main()
{
hello();
return 0;
}
编译:
clang main.c -lhello -o hello
注意需要使用到hello.lib.
生成hello.exe,和hello.dll一起使用即可、