Compiling DLLs with GCC under windows

Source: Internet
Author: User

This program has 3 files, respectively export.h, export.c, MAIN.C

Export.h File Contents

/* This header is necessary, other people know what to do when calling */#ifdef build_dll#define export __declspec (dllexport) #else # define Export __declspec ( dllimport) #endifEXPORT void export (void);

EXPORT.C File Contents

#include <stdio.h> #include "export.h" Export void export (void) {printf ("HELLO dll\n");}

MAIN.C file contents (if only DLL files are compiled, this file is not required to participate)

#include "export.h" int main () {export (); return 0;}

Compiling the build DLL

D:\>gcc-shared-o Export.dll export.c

This DLL is compiled and other programs can be called.

Now compile main.c call this DLL

D:\>gcc-o Main.exe main.c-l./-lexport

Executive Main.exe

D:\>main.exe

HELLO DLL

Compiling DLLs with GCC under windows

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.