Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C DLL In Code::Blocks

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?

like image 559
free_ice_cream Avatar asked Mar 24 '23 21:03

free_ice_cream


2 Answers

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

enter image description here

Then select Dynamic Link Library and away you go.

like image 171
David Heffernan Avatar answered Mar 26 '23 11:03

David Heffernan


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.

like image 27
Neil Roy Avatar answered Mar 26 '23 10:03

Neil Roy