Add a dynamic link library under codeblocks

Source: Internet
Author: User
Manual creation:

(1) file-> new-> project-> dynamic link library;

Name: dynamiclib

Delete the main. cpp file automatically generated by the project, and automatically add a. c File (trydll. c) to delete the main. h file to create a trydll. h file:

Trydll. c:

# Include <stdio. h> # include <string. h> # include "trydll. h "void hello () {printf (" hello \ n "); printf (" xd ");}

Trydll. h:

# Ifndef _ trydll_h00000000ded # define _ trydll_h00000000ded # include <windows. h>/* To use this exported function of dll, include this header * in your project. */# ifdef BUILD_DLL # define DLL_EXPORT _ declspec (dllexport) # else # define DLL_EXPORT _ declspec (dllimport) # endif # ifdef _ cplusplusextern "C" {# endifvoid DLL_EXPORT hello (); # ifdef _ cplusplus} # endif/_ trydll_H __

Compile the project and generate:

\ Dynamiclib \ bin \ Debug:


Test: Create a c project to call the above dynamic library:
Add the trydll. H file and add the above: file to the \ bin \ Debug \ directory under the new trydll project. Compile --> execute ......:
# Include <stdio. h> # include <stdlib. h> # include "trydll. h" int main () {hello (); printf ("Hello world! \ N "); return 0 ;}
Result:

It can be implemented simply by linking the dynamic library.
In addition, add project --> build options-> Debug-> linker settings (generate the file under the path of the dynamic library ):

However, I have not succeeded in this method.

Add a dynamic link library under codeblocks

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.