Labels: C Language
There are two methods to call a dynamic link library DLL file on Windows:
A) Link for implicit loading; use *. lib (Import/Export) file, add the name of the import/export lib file to the relevant settings of the IDE linker, or add pre-compilation instructions to the Program # pragma comment (Lib ,"*. lib ").
B) Explicit runtime link. Use the Load Library () and getprocaddress () functions to load functions in the dynamic library instead of the *. Lib file.
Note that the imported lib file contains the name of the corresponding DLL file. If you use a hexadecimal Editor (such as winhex) to open the imported lib file, you can see the corresponding DLL file name.
On Windows, use the C compiler in Microsoft Visual Studio to generate an OpenSSL dynamic library. The generated file is in the out32dll directory and has four files. The default names are libeay32.lib and libeay32.dll, ssleay32.lib, ssleay32.dll. Here, the suffix Lib is the import and export file corresponding to the DLL of the same name, not the static library file.
Even if the compiled library file is 64-bit, the default file name is the same. If we want to use another name for the generated library file, for example, if we want the 64-bit library file name to be: libeay_x64.lib in sequence, libeay_x64.dll, ssleay_x64.lib, and ssleay_x64.dll. It is feasible to directly modify the file name only when the dynamic library is linked during explicit running, but if the dynamic library is loaded using the Link Method of implicit loading, it is impossible to change the name simply. In this case, if you only change the name, you can use it during compilation. However, even though libeay_x64.dll or ssleay_x64.dll already exists in the executable directory, an error is reported:
"Unable to start this program because libeay32.dll (or ssleay32.dll) is lost in the computer ). Try to reinstall the program to solve this problem ."
It indicates that you still need to find the file before the name change, instead of the file after the name change. The reason is that although the name of the imported libeay32.lib and ssleay32.lib files has been changed to libeay_x64.lib and ssleay_x64.lib, the internal DLL file names of the two files are libeay32.dll and ssleay32.dll. If you use the hexadecimal editor to open these two Import and Export files, you can see that there are still many strings with the ASCII code value libeay32.dll and ssleay32.dll.
To modify the name of the default dynamic library file compiled by OpenSSL, you must perform some special operations when compiling the dynamic library. For compiling OpenSSL, refer to compile.
1) assume that the 32-bit OpenSSL dynamic library file to be compiled is named libeay_x86.lib, libeay_x86.dll, ssleay_x86.lib, and ssleay_x86.dll, as follows:
1.1) Open the configure file with a text editor (such as NotePad ++) in the directory where the source code of OpenSSL is located, and search for the libeay32 string (case-insensitive), which is roughly located in lines 1978th and 1979, you can find the following content:
# If defined (crypto)
Value "internalname", "libeay32 \ 0"
Value "originalfilename", "libeay32.dll \ 0"
Replace all the libeay32 strings with libeay_x86
The following line is followed by the following content:
# Elif defined (SSL)
Value "internalname", "ssleay32 \ 0"
Value "originalfilename", "ssleay32.dll \ 0"
Replace all ssleay32 strings with ssleay_x86
1.2) execute the command
Perl configure VC-WIN32 no-ASM
Ms \ do_ms
1.3) Go To The MS directory, use a text editor to modify the file libeay32.def and find the following line:
Library libeay32
Change this line:
Library libeay_x86
Use the text editor to modify the ssleay32.def file and find the following line:
Library ssleay32
Change this line:
Library ssleay_x86
Modify the file NTDLL. Mak in the text editor and find the following three lines:
E_exe = OpenSSL
SSL = ssleay32
Crypto = libeay32
To:
E_exe = OpenSSL
SSL = ssleay_x86
Crypto = libeay_x86
Note that the first line does not need to be modified. The second and third lines are modified.
1.4) execute the command
Nmake-F Ms \ NTDLL. Mak
The generated dynamic library file name is the expected name, not the default OpenSSL file name.
-----------------------------------------------------------------------------
2) If you want to compile a 64-bit OpenSSL dynamic library file named libeay_x64.lib, libeay_x64.dll, ssleay_x64.lib, and ssleay_x64.dll, perform the following operations:
2.1) Open the configure file in the directory where the source code of OpenSSL is located, search for the string libeay32 (case-insensitive), and find the following content in lines 1978th and 1979:
# If defined (crypto)
Value "internalname", "libeay32 \ 0"
Value "originalfilename", "libeay32.dll \ 0"
Replace all the libeay32 strings with libeay_x64
The following line is followed by the following content:
# Elif defined (SSL)
Value "internalname", "ssleay32 \ 0"
Value "originalfilename", "ssleay32.dll \ 0"
Replace all ssleay32 strings with ssleay_x64
2.2) execute the command
Perl configure VC-WIN64A
Ms \ do_win64a
2.3) Go To The MS directory, use a text editor to modify the file libeay32.def and find the following line:
Library libeay32
Change this line:
Library libeay_x64
Use the text editor to modify the ssleay32.def file and find the following line:
Library ssleay32
Change this line:
Library ssleay_x64
Modify the file NTDLL. Mak in the text editor and find the following three lines:
E_exe = OpenSSL
SSL = ssleay32
Crypto = libeay32
To:
E_exe = OpenSSL
SSL = ssleay_x64
Crypto = libeay_x64
Note that the first line does not need to be modified. The second and third lines are modified.
2.4) execute the command
Nmake-F Ms \ NTDLL. Mak
The generated dynamic library file name is the expected name, not the default OpenSSL file name.
-----------------------------------------------------------------------------
Compile on 64-bit win7 and run the nmake-F Ms \ NTDLL command using Visual Studio 2010. during Mak compilation, both the 32-bit library file and the 64-bit library file encountered the following errors:
Link: Fatal error lnk1123: failed during coff conversion: Invalid or corrupt file
Solution:
Search for the cvtres.exe file on the computer, In the \ windows \ Microsoft. net \ framework and \ Microsoft Visual Studio 10.0 \ Vc can all find the 32-bit file cvtres.exe, and find that the file version in \ Microsoft Visual Studio 10.0 \ Vc is older, rename it or delete it.
In the \ windows \ Microsoft. net \ framework64 and \ Microsoft Visual Studio 10.0 \ Vc \ bin can find 64-bit file cvtres.exe, find that \ Microsoft Visual Studio 10.0 \ Vc \ BIN file version older, rename or delete it.
After nmake-F Ms \ NTDLL. Mak is executed, the error "failed during coff conversion: Invalid or corrupt file" will not be reported.
Modify the name of the default dynamic library file compiled by OpenSSL