How to generate DLL files by GCC in the MinGW?
2009-04-09 21:32
489 查看
How
to generate DLL files by GCC in the MinGW?
[Download and Install pexports]
1.
Download pexports-0.43.zip.
2.
Unzip pexports-0.43.zip.
3.
Download patchfile-1.0.zip.
4.
Unzip patchfile-1.0.zip
5.
Patch all related files.
6.
Build and Install pexports
[Edit hello.h]
[Edit hello.c]
[Build hello.c and generate DLL file]
Notice: The red part can not be separated by
blank spaces.
[Build hello.lib]
1.
Generate hello.def file in terms of hello.dll
2.
Generate hello.lib in the light of hello.def
Ok, Now,
we have generated hello.dll, hello.lib, hello.exp libhello.a, so other program
can use it.
[Summarization]
1.
pexports is a very good tool to generate *.def. It can be used to generate
*.lib when readers only own *.dll.
2. If
readers like the simple way to build *.dll. Appendix A is an alternative
by utilizing Bsymbolic option of ld.exe. Please use “ld --help”
to acquire more information.
[Appendix A]
If
readers do not like pexports tool, gcc can automatically generate *.dll, *.def
and *.a in the same time.
to generate DLL files by GCC in the MinGW?
[Download and Install pexports]
1.
Download pexports-0.43.zip.
2.
Unzip pexports-0.43.zip.
$ unzip.exe pexports-0.43.zip |
Download patchfile-1.0.zip.
4.
Unzip patchfile-1.0.zip
$ unzip.exe patchfile-1.0.zip |
Patch all related files.
$ mv patchfile-1.0 ./pexports-0.43/src/ $ cd ./pexports-0.43/src/ $ patch.exe -p0 < patchfile-1.0 |
Build and Install pexports
$ make $ cp ./pexports.exe /bin/ |
1 #ifndef _HELLO_H 2 #define _HELLO_H 3 4 #if defined( __cplusplus ) || defined( c_plusplus ) 5 extern "C" { 6 #endif 7 8 #ifdef BUILD_DLL 9 #define DLL_API __declspec( dllexport ) 10 #else 11 #define DLL_API __declspec( dllimport ) 12 #endif 13 14 DLL_API void MyDllSay( void ); 15 16 #if defined( __cplusplus ) || defined( c_plusplus ) 17 } 18 #endif 19 20 #endif |
1 #include <stdio.h> 2 #include "hello.h" 3 4 void MyDllSay( void ) 5 { 6 printf( "I am a DLL function generated by GCC in the MinGW./n" ); 7 } |
$ gcc -c -O3 -DBUILD_DLL hello.c $ gcc -shared -o hello.dll hello.o -Wl,--out-implib,libhello.a |
blank spaces.
[Build hello.lib]
1.
Generate hello.def file in terms of hello.dll
$ pexports.exe hello.dll > hello.def |
Generate hello.lib in the light of hello.def
$ lib.exe /machine:i386 /def:hello.def /out:hello.lib |
we have generated hello.dll, hello.lib, hello.exp libhello.a, so other program
can use it.
[Summarization]
1.
pexports is a very good tool to generate *.def. It can be used to generate
*.lib when readers only own *.dll.
2. If
readers like the simple way to build *.dll. Appendix A is an alternative
by utilizing Bsymbolic option of ld.exe. Please use “ld --help”
to acquire more information.
[Appendix A]
If
readers do not like pexports tool, gcc can automatically generate *.dll, *.def
and *.a in the same time.
$ gcc -c -O3 -DBUILD_DLL hello.c $ gcc -shared -Wl,--output-def,hello.def -Wl,--out-implib,libhello.a -Wl,-Bsymbolic -o hello.dll -Wl,hello.o $ lib.exe /machine:i386 /def:hello.def /out:hello.lib |
相关文章推荐
- How to use GCC to build DLL by DEF file in MinGW?
- How to Capture the Integer-Divide-By-Zero Error in C++(提前定义信号)
- How to identify all the Corrupted Objects in the Database reported by RMAN
- How to load the specified mscordacwks.dll for managed debugging when multiple .NET runtime are loaded in one process
- How to Interpret the "SQL ordered by Physical Reads (UnOptimized)" Section in AWR (文档 ID 1466035.1)
- How to compile GCC-4.3.3 in the cygwin?
- How to organize the Template Files in C++
- How to import dll in c# that can be accessed by [DllImport]
- How to sort by a form that is not displayed in the document in MicroStrategy Desktop 8.x
- How to avoid Excel from prompting "The file you are trying to open, , is in a different format than specified by the file extension"? (转)
- how to manually traverse the ZODB tree in your code to locate objects by their path?
- How To Check Whether Physical Standby is in Sync with the Primary or Not?
- How to .gitignore all files/folder in a folder, but not the folder itself?
- (极力推荐)BW:How to load and generate a custom hierarchy in SAP Business Warehouse (SAP BW) without using flat files
- How to get files to show up in the Process Monitor/Report Repository
- Problem 15 - Starting in the top left corner in a 20 by 20 grid, how many routes are there to the bottom right corner?
- How to see the Physical SQL generated by a request in Presentation Service ?
- HOWTO Install the MinGW (GCC) Compiler Suite
- How to compile opencore-amr in the MINGW
- How to grant access to SQL logins on a standby database when the guest user is disabled in SQL Serve