如何创建现有C项目的DLL文件 [英] How to create a DLL file of an existing C project

查看:84
本文介绍了如何创建现有C项目的DLL文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个C项目正在生成一个.exe作为输出.由于我需要创建现有项目的DLL文件,因此任何一个plz都能为我提供帮助.

Hi,
I am having a C project which is generating an .exe as output.Since i require to create a DLL file of the existing project so can any one plz help me.Thanks in advance. sorry fr inappropriate English.

推荐答案

实际上,如果我们单独使用__declspec(dllexport),则编译器将进行名称整形,因此我们还必须使用extern"C"创建一个完美的C-DLL

从DLL导出功能的另一种方法是编写DEF文件.
假设您拥有Fun_1(),Fun_2(),则可以在V.Studio中通过
创建DEF文件
添加新项目->代码->模块定义定义项(.def)"

在def文件中:

Actually if we use __declspec(dllexport) alone, then compiler will do name mangling, so we have to use extern "C" also to create a perfect C-DLL

An alternative to export functions from DLL is to write a DEF file.
Say you are having Fun_1(), Fun_2(), then you can create a DEF file in V.Studio by

Add "New Item --> code --> Module-definition dile (.def)"

Inside the def file:

LIBRARY   CDLL
EXPORT

Fun_1
Fun_2



这将导出Fun_1& Fun_2,没有名称修改.



This will export Fun_1 & Fun_2 without name mangling.


假设您使用的是Visual Studio,首先,要生成要导出为``__declspec(dllexport)''的make函数,例如,

Assuming you are using Visual Studio, First of all make functions you want to export as ''__declspec(dllexport)'', e.g,

__declspec(dllexport) void __cdecl Fun1();



现在,转到项目"菜单,选择"项目属性".

在配置属性中->一般->配置类型为动态库(.dll)

编译代码,您将在输出目录中找到创建的.dll和.lib文件.

问候



Now, go to Project menu, select Project properties.

In Configuration Properties --> General --> Configuration Type as Dynamic Library (.dll)

Compile your code, you will find .dll and .lib file created in your output directory.

Regards


这篇关于如何创建现有C项目的DLL文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆