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?
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With