您的位置:首页 > 编程语言 > C语言/C++

c 语言 dll编译与使用

2016-05-05 22:00 357 查看
首先,上一条博客。 http://blog.sina.com.cn/s/blog_62c832270101d92u.html 根据博客中的步骤,可以使用C语言编写dll并于main函数中调用。作死的时候来了:win8,mingw32,4.9.3 gcc在.h中写一段代码:/*test.h*/
#include <stdio.h>

void hello()
{
printf("Hello from DLL\n");
}
编译,生成test.dll文件。生成完成。编写main函数:/*main.c*/
#include <stdio.h>
int main()
{
hello();

return 0;
}
执行,报错:百思不得其解。尝试向文件中添加:/*test.h*/
#include <stdio.h>
__declspec(dllexport)
void hello()
{
printf("Hello from DLL\n");
}
/*main.c*/
#include <stdio.h>__declspec(dllimport) void hello();int main(){hello();return 0;}
编译,仍然报错:查看相关文档,似乎.h文件与.c文件并没有什么太大区别。。 http://www.cnblogs.com/laojie4321/archive/2012/03/30/2425015.html 老实的将.h改回.c,可以运行。再次进行以下实验:/*zuo.h*/
#include <stdio.h>int main(){printf("zuo si\n");return 0;}
编译,生成zuo.exe:运行zuo.exe:运行报错。总结:.c与.h文件存在差别,原因不明。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c语言 dll mingw