DLL generated by mingw in window

Source: Internet
Author: User
Tags microsoft c

Mingw refers to the compilation environment for generating pure Win32 executable files using only free software. It is a nickname of minimalist GNU on Windows. For more information, see <>.
Here "pure" refers to "applications using msvcrt. dll 」. Microsoft Foundation Classes cannot be used ).
Mingw: a Windows-specific header file that can be freely used and released, and a collection of imported data using the GNU tool set. This allows you to generate local Windows programs without the need for a third-party C Runtime Library.
Mingw, that is, minimalist GNU for Windows. It is a collection of header files and port libraries that allow people to use GCC (GNU Compiler C) to generate windows32 programs without a third-party dynamic link library.

In the basic layer, mingw is a group of files and port libraries. Its function is to allow console-mode programs to use Microsoft's Standard C Runtime Library (msvcrt. DLL), the Library is valid on all nt OS, effective on all Windows OS Versions later than Windows 95, use the basic running time, you can use the GCC write Console mode to conform to the American Organization for Standardization (ANSI) program, and use the C Runtime extension provided by Microsoft. This function is not available for Windows 32 APIs. The next component is the w32api package, which is a group of files and port libraries that can use windows32 APIs. Combined with the basic running time, you can have full rights to use both
CRT (C Runtime) also uses the windows32 API function.
The official mingw website is
In fact, mingw is not a C/C ++ compiler, but a set of GNU tools. Apart from GCC (GNU Compiler set), mingw also contains some other gnu program development tools (such as gawk bison ).

Mingw is developed to provide a GNU working environment for those who do not like to work in the Linux (FreeBSD) operating system and stay in windows.
(Although the previous cygwin is also a GNU Windows Port, cygwin is copyrighted, not GNU .)
Therefore, with mingw, we can use the GNU program development tool as in Linux.
GCC is the core of mingw. GCC is a compilation system that supports many computer programming languages, and is the closest to the standard in terms of implementation of language standards. In addition, GCC can be transplanted to almost all currently available computer platforms. (Devkitpro is also installed on my computer, which contains the GCC arm (for GBA/DS/gp32) and MIPS (for PSP) versions .)

GCC itself does not have the IDE interface as VC does (in Windows There are also Dev C ++ and other ides that support mingw compiler ). You can select any text editor you like to edit the source code (it is said that Microsoft developers, including VC, do not use the IDE editor provided by VC, but choose the GNU Vim editor ). Then, use make and other tools to compile, Link, package, and publish software projects. Source code version control tools like CVS (SVN) allow anyone in any corner of the world to participate in software projects.

For the MFC and Microsoft basic library classes, this open source code development kit with VC ++ is the same as other Windows Development kits. If you have VC ++ authorization, you can use the source code of MFC, that is, you can use GCC to compile the MFC program.

Of course, there are also many windows Development kits under GNU, and some of them support cross-platform use. You can not only directly compile the source code into a Windows program, but also compile it into a graphical program of other operating systems without modification.

However, the most popular GUI development library under GNU is GTK +. GTK + can also run well on Windows platforms (such as Gimp and GAIM ).
In general, using mingw is GNU.

Basic usage:
It is very convenient to generate and use DLL in the mingw environment.
1. generate DLL
GCC (G ++)-shared-O test. dll test. C (test. cpp)
Use this command to generate test. dll and export non-static functions and related classes in test. C.

(Note by asper: This command line is invalid when processing the DLL involved in JNI)
I use the Microsoft C ++ compiler. The CL command is invalid for paths with spaces and must be enclosed "".

2. Connect the DLL to the exe.
Mingw uses DLL in the same way as static library. A. You only need to add-ltest to the connection without the Lib prefix.
3. Compile the DLL called by JNI
You have a solution! Yes. The GCC parameter is missing. As follows:
Gcc-I % java_home % \ include \ Win32-wl, -- add-stdcall-alias-shared-o call. dll call. c

Parameter:-wl, -- add-stdcall-alias can add a standard call prefix (stdcall @ NN) to the function ).
In this way, you can compile the DLL. We all know that the functions in Win32 dll must have a standard call prefix. In JNI, it is not convenient to manually handle this. Sun did not make it clear that the compiler is responsible for this. So I am very depressed. After searching for more than half a month, I finally found the answer on a very old web page.

Basically similar to the VC interface, the most commonly used C language is VC ++ 6.0.

If it is helpful to you, please remember to adopt a satisfactory answer. Thank you! Wish you a happy life!

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.