简体   繁体   English

Code :: Blocks中的C DLL

[英]C DLL In Code::Blocks

I can't find anything about how to make a C DLL in Code::Blocks. 我找不到任何关于如何在Code :: Blocks中制作C DLL的内容。 Whenever I try and look it up it shows links to using C++ DLLs in managed programming languages. 每当我尝试查找它时,它都会显示在托管编程语言中使用C ++ DLL的链接。 And Code::Blocks doesn't give an option for a C DLL. 并且Code :: Blocks没有为C DLL提供选项。 What do I do? 我该怎么办?

File->New->Project to show this dialog: 文件 - >新建 - >项目显示此对话框:

在此输入图像描述

Then select Dynamic Link Library and away you go. 然后选择动态链接库,然后离开。

In Code::Blocks you create a new project, then select Dynamic Link Library (note: you can also, more easily create a Static Link Library, which is also available) and follow the prompts (as stated above). 在Code :: Blocks中,您可以创建一个新项目,然后选择Dynamic Link Library(注意:您也可以更轻松地创建一个静态链接库,也可以使用)并按照提示进行操作(如上所述)。

In order to change your files from C++ to C, make sure the extension is .c not .cpp. 要将文件从C ++更改为C,请确保扩展名为.c而不是.cpp。 Then you can right click on the included .c files (in the left column), select properties then under the Advanced tab you can change the compiler variable from "CPP" to "CC" and it will compile it using the C compiler. 然后,您可以右键单击包含的.c文件(在左栏中),选择属性,然后在“高级”选项卡下,您可以将编译器变量从“CPP”更改为“CC”,它将使用C编译器对其进行编译。 You will need to do this with each file in your project if you initially loaded them as CPP files. 如果最初将它们作为CPP文件加载,则需要对项目中的每个文件执行此操作。 Edit: The COMPILER doesn't care about the filename extension, but the IDE you are using (Code::Blocks) DOES. 编辑:COMPILER不关心文件扩展名,而是您正在使用的IDE(Code :: Blocks)DOES。 The IDE will choose which compiler to use (GCC for C, and G++ for C++) based on the filename extension. IDE将根据文件扩展名选择要使用的编译器(GCC for C和G ++ for C ++)。 It will choose the C++ compiler if your filename ends in .cpp, where as it will choose the C compiler by default if the extension ends in .c. 如果您的文件名以.cpp结尾,它将选择C ++编译器,因为如果扩展名以.c结尾,它将默认选择C编译器。

The Static Library option (further down the list on the selection screen) is an easier option if having a DLL is not that important to you. 如果拥有DLL对您来说不重要,则静态库选项(在选择屏幕上的列表下方)是一个更容易的选项。 You simply load in your files, compile them and you're done. 您只需加载文件,编译它们就可以了。 You don't have to redo your functions in any way or have a special header for it. 您不必以任何方式重做您的功能或具有特殊标头。 It will create a library for you with the .a extension you can then link to your projects. 它将为您创建一个带有.a扩展名的库,然后您可以链接到您的项目。 The beauty is you won't need to provide a DLL file separately. 美丽的是你不需要单独提供DLL文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM