C DLL In Code::Blocks

房东的猫 提交于 2021-01-27 12:36:30

问题


I can't find anything about how to make a C DLL in Code::Blocks. Whenever I try and look it up it shows links to using C++ DLLs in managed programming languages. And Code::Blocks doesn't give an option for a C DLL. What do I do?


回答1:


File->New->Project to show this dialog:

enter image description here

Then select Dynamic Link Library and away you go.




回答2:


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).

In order to change your files from C++ to C, make sure the extension is .c not .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. You will need to do this with each file in your project if you initially loaded them as CPP files. Edit: The COMPILER doesn't care about the filename extension, but the IDE you are using (Code::Blocks) DOES. The IDE will choose which compiler to use (GCC for C, and G++ for C++) based on the filename extension. 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.

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. 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. The beauty is you won't need to provide a DLL file separately.



来源:https://stackoverflow.com/questions/16668552/c-dll-in-codeblocks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!