0
votes

I would like to use OpenSSL in a VC++ project. But i can not statically link the libraries. Let me first talk about how I did it.

1, Download openssl-1.1.1h.tar.gz and extract it to "d:\openssl\sources\openssl-1.1.1h"

2, Build OpenSSL in Visual Studio 2019 Tools Command Prompt

enter image description here

enter image description here

After built successfully, i found 4 dirs in "d:\openssl\builds\openssl-1.1.1h-VC-WIN32" After built

And there are two libraries in "d:\openssl\builds\openssl-1.1.1h-VC-WIN32\lib" enter image description here

enter image description here

3, Create an empty VC++ project in VS2019 enter image description here

4, Add Program.cpp and add codes in Program.cpp enter image description here

5, Add static libraries by according How to add static libraries to a Visual studio project enter image description here enter image description here enter image description here

6, Debug and then i met error enter image description here

Why did it look for "libssl-1_1.dll"? I linked "libssl.lib" statically! I can not find the reason, please help me!

I met "fatal error LNK1120: 28 unresolved externals" if i configure it with "no-shared"

enter image description here

enter image description here

According to Unresolved symbols when built statically for Visual Studio this problem can be solved by add below codes

#pragma comment(lib, "crypt32")
#pragma comment(lib, "ws2_32.lib")

It can be solved according Add dependencies for "ws2_32.lib" and "crypt32.lib"

enter image description here

1

1 Answers

1
votes

The .lib files that are created in a default build are just stubs to call the dlls.

When building OpenSSL you need to specify that you want to build it for static linking.

Modify the "Configure" line that you used to add "no-shared" onto the end, e.g.

perl Configure --prefix=d:\your\prefix\here VC-WIN32 no-shared

Then you will need to rebuild OpenSSL:

nmake clean
nmake
nmake test
nmake install