且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Visual Studio / Codeblocks中添加openssl库

更新时间:2023-02-21 09:45:02

这取决于你是否有静态库文件(.lib)或只有源代码(.c)



如果你只有c文件,那么你可以添加它们您的项目并将头文件包含在您需要的位置。 如何:将现有项目添加到项目中 [ ^ ]



如果您有库文件,请参阅此链接: MSDN:.Lib文件作为链接器输入 [ ^ ]



[更新]

要将内容的内容从一个变量复制到另一个变量,您可以使用memcpy_s [ ^ ]



  char  szSha1Value [ 40 ]; 
memcpy_s(szSha1Value, sizeof (szSha1Value),* arr,strlen(* arr));



(不完全确定arr的解除引用是否正确,请参阅指针 [ ^ ])


这里 [ ^ ]是Windows的构建说明(32位,有64位的不同文档)。在构建并安装openssl库之后,将包含路径(openssl / include或inc32 /)添加到Visual Studio库路径,并将库二进制路径(openssl / lib或out32dll /)添加到链接器路径。



还有预编译版本可用 [ ^ ],附带安装程序,因为它必须安装几个部件。


我知道它很长时间都很难用。我安装了openssl-1.1.0h并使其适用于Visual Studio 2017

我在c:\ opennssl-1.1.0h中创建了一个子文件夹,并将openssl文件放在这个文件夹中。

(我使用西班牙语的Visual Studio,因此某些菜单选项可能没有正确命名)。这是我的经验,不是真正的教程。这是很多工作。

以下是步骤:



I.-我下载OpenSSL(openssl-1.1.0h) ,PERL和NASM



II.-我安装了PERL和NASM



III.-我安装了OpenSSL ,但这并不容易

1)我打开一个控制台窗口,但不是正常的(不是控制台通过编写cmd或类似的东西得到)

我打开一个来自本机工具的控制台,这是visual studio的子文件夹:

开始 - >所有程序 - > Visual Studio 2017-> Visual Studio工具 - > VC-> Native的系统符号工具x64

2)cd \openssl-1.1.0h

3)路径c; \program files \ nasm \;%path%;

4)ppm安装dmake

5)perl配置VC-WIN64A

6)nmake

7)nmake test

8)nmake install

最后它可以安装!!!



IV.-当我试图编译视觉工作室中的sw它没有com桩。库文件存在链接器问题(我猜libcrypto.lib)。

1)项目的属性页面 - >链接器 - >输入 - >附加依赖项。

包含路径的文件需要写在这里,在我的例子中:
 C:\openssl-1.1.0h \ libcrypto.lib 

2)使用Visual Studio中包含的控制台工具,我分析了这个文件: Dumpbin

我分析了dumbin的报告,我意识到库文件是针对x64的,所以我不得不在Visual Studio中创建一个x64配置。

这也不自然:...



V.- x64编译。我发现这个帮助网页(西班牙文)



1)在Visual Studio 2017中 - &gt ;;编译 - &gt ;;配置管理器

2)在配置活动解决方案时我让调试(初始值)和在活动配置平台中我选择新建,然后在写入或选择新平台字段中打开一个新窗口

3)我选择win32并在我从中选择复制配置字段中选择x64和我点击接受。活动窗口关闭。

4)之后的最后一个窗口,有项目上下文列表(在我的情况下只有一个上下文可用)我让调试 在配置字段中,在我选择的平台x64中,我点击关闭按钮

5)我关闭项目compl ete和我再次打开(我不确定这是否有必要,但我做到了并且有效)

6)之后我编译了项目.....



项目没有编译,但错误列表现在不同了。找不到openssl包含文件。原因是

包括openssl文件夹没有添加到项目中。我在项目中添加openssl-1.10h和openssl-1.10h \ include。

为此,我执行以下步骤。

1)在选择项目的解决方案资源管理器中(这意味着解决方案的一个级别)我点击了扳手图标(获得项目的财产)

2)在配置属性 - > VC目录 - >包含文件目录我添加了文件夹openssl-1.10h和openssl-1.10h\include

3)我再次编译并且项目编译不正确,但现在编译报告一些PDB文件丢失(我在一个论坛中读到这些文件并不那么重要),然后是一条消息,表明项目与代码关系密切(0xc0000135)。这是一个文件丢失,但编译报告没有识别。要知道文件是什么,我必须使用一个工具。这个工具需要下载并放在一个文件夹上(安装非常简单,没有添加图标,只下载并复制到文件夹中):

依赖沃克。在文件夹中我执行了文件depends.exe。

4)我在菜单中选择文件打开选项

5)在打开的窗口中,有5个面板可用。其中一些是干净的,另一个是树(如文件夹树)一个文件缺少一个

黄色图标和一条消息说文件丢失(libcrypto-1_1-x64.dll)。我双击了这个文件,文件被查找

在文件夹中找到了我的项目的exe文件。

6)我复制了我的项目(myproject.exe)的(libcrypto-1_1-x64.dll)文件.exe文件。任何一些文件丢失的方法,但我想这并不重要。

7)我再次编译项目

和项目Compiled !!!!!


Sir,I have searched in google for finding SHA(Secure Hash Algorithm) using C program and came to know about Openssl library which is to be used for finding SHA etc.,

I have downloaded Openssl binary Rar file and extracted it.But I don't know how to add Openssl library to my visual studio because I need this header file for finding SHA

#include <openssl/sha.h>



On extracting the openssl rar fie I see many folder, c source and header files which is quite confusing.

I usually prefer codeblocks for programming with C and C++ so I don't know how to add those libraries in visual studio.
What should I do now?
Is there any other better ways for finding SHA using C/C++ programming even manually?

Kindly help me with this.

It depends if you have static library files (.lib) or only source code (.c)

If you only have c-files, then you can add them to your project and include the header files where you need to. How to: Add Existing Items to a Project[^]

If you have library files, see this link: MSDN: .Lib Files as Linker Input[^]

[UPDATE]
To copy the contents of the contents from one variable to another you can use memcpy_s[^]

char szSha1Value[40];
memcpy_s(szSha1Value, sizeof(szSha1Value), *arr, strlen(*arr));


(Not exactly sure if the dereferencing of arr is correct, see Pointers[^])


Here[^] are the build instructions for Windows (32bit, there's a different doc for 64bit). After you've built and installed the openssl libraries, add the include paths (openssl/include or inc32/) to your Visual Studio library paths and the library binary paths (openssl/lib or out32dll/) to your linker paths.

There are also pre-compiled versions available[^], comes with an installer since it has to install several parts.


I get it it was hard work for a long time. I installed openssl-1.1.0h and make it works with Visual Studio 2017
I create a subfolder in c:\openssl-1.1.0h and put the files of openssl in this folder.
(I have Visual Studio in Spanish, so it is possible that some menu option are not correctly named). This is my experience, not really a tutorial. It was a lot of work.
The following are the steps:

I.- I Download OpenSSL (openssl-1.1.0h), PERL and NASM

II.- I installed PERL and NASM

III.- I installed OpenSSL, but it was not easy
1) I open a console windows, but not the normal (not the console get by writing cmd or somesthing like that)
I open a console from native Tool, this is a subfolder from visual studio:
Start->All Programs->Visual Studio 2017->Visual Studio Tools->VC->System Symbol of Native Tools x64
2) cd \openssl-1.1.0h
3) path c;\program files\nasm\;%path%;
4) ppm install dmake
5) perl Configure VC-WIN64A
6) nmake
7) nmake test
8) nmake install
And finally it works the installation!!!

IV.- When I tried to compile the sw in visual studio it did not compile. There was a linker problem with a library file (I guess libcrypto.lib).
1) Property Page of the Project->Linker->Input->Additional Dependences.
The file including the path need to be written here, in my case:
C:\openssl-1.1.0h\libcrypto.lib

2) With a console tool included in Visual Studio I analyzed this file: Dumpbin
I analyzed the report of the dumbin and I realized that the library file was for x64, so I had to create a x64 configuration in Visual Studio.
This was also not natural:...

V.- Compilation for x64. I found this help web page (in spanish)

1) In visual Studio 2017 ->;Compile->;Configuration Manager
2) In Configuration of Active Solution I let "Debug" (the initial value) and in Platform of Active Configuration I selected "New", and then a new windows opened
3) in the field "write or select the new platform" I select "win32" and in the field "Copy the configuration from" I selected x64 and I click in Accept.The active windows was closed.
4) After that the last windows, that has the list of project context (in my case only one context was available) I let "Debug" in the Configuration field, and in the Platform I selected "x64" and I click on close button
5) I close the project complete and I opened again (I am not sure if this is necessary, but I did it and works)
6) After that I compiled the project.....

The project did not compile, but the error list was different now.The openssl include files were not found. The reason was that the
include openssl folder was not added to the project. I add openssl-1.10h and openssl-1.10h\include to the project.
To do this I carry out the following steps.
1) In solution explorer with the project selected (this means one level bellow the solution) I clicked on the spanner icon (to get the property of the project)
2) In configuration property-> VC Directory->Include file directory I added the folders openssl-1.10h and openssl-1.10h\include
3) I compile again and the project did not compile properly, but now the compile report some PDB files missing (I read in a forum that those files were not so important) and after that a message that the project was close with the code (0xc0000135). This was a file missing, but there was not identificated by the compile report. To know what was the file I had to use a tool for this. This tool needs to be downloaded and put on a folder (installation was very easy, not icon was added, only downloaded and copied in a folder):
Dependency Walker. In the folder I executed the file "depends.exe".
4) I select the file open option in the menu
5) In a windows opened, 5 panels are available. Some of them were clean and in other was a tree (like folders tree) a file missing with a
yellow icon and a message that say the file was missing (libcrypto-1_1-x64.dll). I double clicked on this file and the file was looked for
in the folder were the exe file of my project was found.
6) I Copied the (libcrypto-1_1-x64.dll) file .exe file of my project (myproject.exe). Any ways some files were missing, but I guess this was not important.
7) I compiled the project again
And the project Compiled!!!!!