手动创建:
(1)file->new->project->dynamic link library;
名字:dynamiclib
将工程自动生成的main.cpp文件删除,自动添加一个.c文件(trydll.c) 将main.h 文件删除 创建一个trydll.h文件:
trydll.c:
#include <stdio.h>
#include <string.h>
#include "trydll.h"
void hello(){
printf("hello\n");
printf("xd");
}
trydll.h:
#ifndef __TRYDLL_H__INCLUDED
#define __TRYDLL_H__INCLUDED
#include <windows.h>
/* To use this exported function of dll, include this header
* in your project.
*/
#ifdef BUILD_DLL
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT __declspec(dllimport)
#endif
#ifdef __cplusplus
extern "C"
{
#endif
void DLL_EXPORT hello();
#ifdef __cplusplus
}
#endif
#endif // __trydll_H__
将工程编译,生成:
\dynamiclib\bin\Debug下:
测试:
创建一个c工程,实现上面动态库的调用:
将trydll.h文件添加进去 并且将上面的:
文件 添加到新的trydll工程下的 \bin\Debug\目录下。
编译-->执行......:
#include <stdio.h>
#include <stdlib.h>
#include "trydll.h"
int main()
{
hello();
printf("Hello world!\n");
return 0;
}
结果:
可以简单的实现:链接动态库的方法。
还有就是在:project-->build options->Debug->linker settings 添加(生成动态库那个路径下的文件):
但是 此方法 我没有实现成功,还望大神们指点。