Modify the name of the dynamic library file that OpenSSL compiles by default

Source: Internet
Author: User
Tags visual studio 2010

There are two ways to invoke a dynamic-link library DLL file on a Windows platform:
A) implicit load-time linking; use the *.lib (import library) file to include the name of the import library lib file in the IDE's linker related settings, or add the precompiled Directive #pragma comment (lib, "*.lib") to the program.
b) Explicit run-time linkage. Instead of using the *.lib (import library) file, use the load library (), GetProcAddress () function to load the functions in the dynamic library.
Note that in the inbound Lib file contains the name of its corresponding DLL file, if you use the 16-input editor (such as WinHex) to enlighten the library Lib file, you can see the corresponding DLL file name.

On the Windows platform, use the C compiler in Microsoft Visual Studio to generate a dynamic library of OpenSSL, the resulting file in the Out32dll directory, with four files, the default name is: Libeay32.lib,libeay32.dll,sslea Y32.lib,ssleay32.dll. Here the Lib suffix is the same name DLL corresponding to the import library file, not a static library file.
Even if the compiled library file is 64-bit, the default file name is the same, if we want to generate a library file to take another name, such as the 64-bit library file name to be: Libeay_x64.lib,libeay_x64.dll,ssleay_ X64.lib,ssleay_x64.dll, directly modifying the file name is only feasible when linking the dynamic library explicitly at runtime, but if you load the dynamic library using implicit load-time linking, simply renaming is not a good option. At this point, if you simply rename the name, you can pass it at compile time, but at run time, although Libeay_x64.dll or Ssleay_x64.dll already exists in the executable directory, an error will be reported:
"This program cannot be started because Libeay32.dll (or Ssleay32.dll) is missing from the computer. Try reinstalling the program to resolve this issue. ”

Note that the runtime or to find the name of the file before renaming, but not to find the renamed file. The reason is that although the name of the import library libeay32.lib,ssleay32.lib has been modified to libeay_x64.lib,ssleay_x64.lib, the internal corresponding DLL file name in these two files is Libeay32.dll and Ssleay32.dll. If you open both import library files with the 16-in editor, you can see that there are also many strings with ASCII values of libeay32.dll,ssleay32.dll inside them.

To modify the name of the dynamic library file that OpenSSL compiles by default, you must perform some special operations when compiling the dynamic library. For the compilation of OpenSSL, you can refer to http://blog.csdn.net/henter/article/details/8364532, the following mainly describes how to change the compiled dynamic library file name.
1) Assume that the 32-bit OpenSSL dynamic library file names that you want to compile are libeay_x86.lib,libeay_x86.dll,ssleay_x86.lib,ssleay_x86.dll, and operate as follows:

1.1) in the directory of OpenSSL source code, using a text editor (such as notepad++) to open the Configure file, search string libeay32 (not case-sensitive), approximate position in the 1978th, 1979 lines, you can find the following:
#if defined (CRYPTO)
VALUE "InternalName", "libeay32\\0"
VALUE "OriginalFilename", "libeay32.dll\\0"
Replace all of the libeay32 strings with libeay_x86

The following lines are immediately followed:
#elif defined (SSL)
VALUE "InternalName", "ssleay32\\0"
VALUE "OriginalFilename", "ssleay32.dll\\0"
Replace all of the ssleay32 strings with ssleay_x86

1.2) Execute the command
Perl Configure Vc-win32 No-asm
Ms\do_ms

1.3) Enter the MS directory, modify the file libeay32.def with a text editor, and locate the following line:
LIBRARY LIBEAY32
Replace this line with the following:
LIBRARY libeay_x86

To modify the file ssleay32.def with a text editor, locate the following line:
LIBRARY SSLEAY32
Replace this line with the following:
LIBRARY ssleay_x86

To modify the file Ntdll.mak with a text editor, find the following three lines:
E_exe=openssl
Ssl=ssleay32
Crypto=libeay32
Modified to:
E_exe=openssl
Ssl=ssleay_x86
Crypto=libeay_x86
Note that the first line does not have to be modified, and the second and third lines are changed.

1.4) Execute the command
Nmake-f Ms\ntdll.mak
The resulting dynamic library file name is the desired name, not the default file name of OpenSSL.

-----------------------------------------------------------------------------
2) If you wish to compile the 64-bit OpenSSL dynamic library file names as Libeay_x64.lib,libeay_x64.dll,ssleay_x64.lib,ssleay_x64.dll, proceed as follows:

2.1) in the directory of the source code of OpenSSL, open the Configure file with a text editor, search the string libeay32 (case-insensitive), the approximate position in the 1978th, 1979 lines to find the following:
#if defined (CRYPTO)
VALUE "InternalName", "libeay32\\0"
VALUE "OriginalFilename", "libeay32.dll\\0"
Replace all of the libeay32 strings with libeay_x64

The following lines are immediately followed:
#elif defined (SSL)
VALUE "InternalName", "ssleay32\\0"
VALUE "OriginalFilename", "ssleay32.dll\\0"
Replace all of the ssleay32 strings with ssleay_x64

2.2) Execute the command
Perl Configure vc-win64a
ms\do_win64a

2.3) Enter the MS directory, modify the file libeay32.def with a text editor, and locate the following line:
LIBRARY LIBEAY32
Replace this line with the following:
LIBRARY libeay_x64

To modify the file ssleay32.def with a text editor, locate the following line:
LIBRARY SSLEAY32
Replace this line with the following:
LIBRARY ssleay_x64

To modify the file Ntdll.mak with a text editor, find the following three lines:
E_exe=openssl
Ssl=ssleay32
Crypto=libeay32
Modified to:
E_exe=openssl
Ssl=ssleay_x64
Crypto=libeay_x64
Note that the first line does not have to be modified, and the second and third lines are changed.

2.4) Execute the command
Nmake-f Ms\ntdll.mak
The resulting dynamic library file name is the desired name, not the default file name of OpenSSL.

-----------------------------------------------------------------------------
Compile on 64-bit Win7, use Visual Studio 2010, execute command nmake-f Ms\ntdll.mak whether compiling 32-bit library files or 64-bit library files, you have encountered the following error:
Link:fatal Error LNK1123: Failed during transition to COFF: invalid or corrupt file

The workaround is to:
Search for Cvtres.exe files on your computer, find 32-bit files under directory \WINDOWS\Microsoft.NET\Framework and \microsoft Visual Studio 10.0\VC Cvtres.exe, discover \ Microsoft Visual Studio 10.0\VC has an older version of the file, renaming it or deleting it.
64-bit files can be found under catalog \windows\microsoft.net\framework64 and \microsoft Visual Studio 10.0\vc\bin Cvtres.exe, Discover \microsoft Visual Studio 10.0\vc\bin has an older version of the file, renaming it or deleting it.
The "failed during transition to COFF: invalid or corrupt file" error is not reported when Nmake-f Ms\ntdll.mak is executed.

http://blog.csdn.net/henter/article/details/39576419

Modify the name of the dynamic library file that OpenSSL compiles by default

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.