如何将 Crypto++ 库添加到 Qt 项目中 [英] How to add Crypto++ library to Qt project

查看:56
本文介绍了如何将 Crypto++ 库添加到 Qt 项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下载了 Crypto++ 源代码并在 Visual Studio 2013 中编译了 cryptlib 项目,然后我将生成的 .lib 文件添加到我的 Qt 项目中,这使我的 .pro 文件看起来像这样:

I downloaded the Crypto++ source and compiled the cryptlib project in Visual Studio 2013, and then I added the generated .lib file to my Qt project, which made my .pro file look like this:

QT       += core gui

QT += sql

greaterThan(QT_MAJOR_VERSION, 4):QT += widgets

TARGET = untitled
TEMPLATE = app


SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h \
        databasecontrol.h \
    test.h

FORMS    += mainwindow.ui

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/ -lcryptlib
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/ -lcryptlibd
else:unix: LIBS += -L$$PWD/ -lcryptlib

INCLUDEPATH += $$PWD/
DEPENDPATH += $$PWD/

win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/libcryptlib.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/libcryptlibd.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/cryptlib.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/cryptlibd.lib
else:unix: PRE_TARGETDEPS += $$PWD/libcryptlib.a

在将这个库添加到项目后,我立即构建它并收到以下错误:

Immediately after adding this library to the project, I build it and get the following error:

:-1: 错误:没有规则可以制作目标 'C:/Users/Special Services/WorkOrder/libcryptlibd.a','debug\untitled.exe' 需要.停止.

我相信我明白错误告诉我我需要一个额外的行,其中所有 else:win32 行都在 DEPENDPATH 下...因为添加的行使用了 $$PWD,这不是 Unix 命令吗?我查看了此错误的其他实例,我相当确定问题出在此处的 .pro 文件中.

I believe I understand that the error is telling me that I need an additional line where all of the else:win32 lines are under DEPENDPATH... or is it because the lines that were added use $$PWD, isn't that a Unix command? I've looked around at other instances of this error and I'm fairly certain the problem is with something in the .pro file here.

我决定采取不同的方法.我去掉了任何导入库添加到我的 .pro 文件中的东西,而是将这行代码放在它的位置:

I decided to take a different approach. I got rid of anything that importing a library added to my .pro file, and instead just put this line of code in its place:

win32:LIBS += C:\Qt\5.2.1\mingw48_32\include\cryptopp\Win32\Output\Debug\cryptlib.lib(cryptlib.lib 文件的路径)

win32:LIBS += C:\Qt\5.2.1\mingw48_32\include\cryptopp\Win32\Output\Debug\cryptlib.lib (The path to the cryptlib.lib file)

这个构建得很好.我确保所有的 cryptopp 头文件都在我的包含目录中,C:\Qt\5.2.1\mingw48_32\include\cryptopp

This built just fine. I made sure that all of the cryptopp header files were in my include directory, C:\Qt\5.2.1\mingw48_32\include\cryptopp

然后我尝试使用 #include <cryptopp/aes.h> 包含一个文件,它构建得很好.我第一次构建时,有 40 多个警告,但我第二次构建时,却没有任何警告.

I then tried to include a file, with #include <cryptopp/aes.h> and it built fine. The first time I built, there were 40+ warnings, but the second time I built, it built without any.

推荐答案

win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/libcryptlib.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/libcryptlibd.a

在 Visual Studio 下的 Windows 上,Crypto++ 库的名称是 cryptlib.lib,而不是 libcryptlib.a.如果您使用了 Cygwin(我不相信您使用过),那么名称​​应该libcryptopp.a.

On Windows under Visual Studio, the name of the Crypto++ library is cryptlib.lib, not libcryptlib.a. If you used Cygwin (which I don't believe you did), then the name would be libcryptopp.a.

libcryptlibd.a(注意添加了d)可能不正确.它代表调试",它是多年前在 Visual Studio 5.0/6.0 中使用的东西.它基于 将 Crypto++ 编译并集成到Microsoft Visual C++ 环境.如果你将Win32/Debug/cryptlib.lib重命名为Win32/Debug/cryptlibd.lib,那么如果你的路径没问题,你可能没问题.

The libcryptlibd.a (notice the addition of the d) is probably not correct. It stands for 'debug', and its something that was used years ago in the Visual Studio 5.0/6.0 days. It was based on Compiling and Integrating Crypto++ into the Microsoft Visual C++ Environment. If you renamed Win32/Debug/cryptlib.lib to Win32/Debug/cryptlibd.lib, then you are probably OK if your paths are OK.

我认为现在推荐的做事方式是使用 cryptlib.lib 作为库(到处都是同名),并根据配置更改链接器路径.路径将是:

I think the recommended way of doing things now is to use cryptlib.lib as the library (same name everywhere), and change the linker paths based on the configuration. The paths would be:

  • Win32,调试:/Win32/Debug/
  • Win64,调试:/x64/Debug/
  • Win32,发布:/Win32/Release/
  • Win64,发布:/x64/Release/

这是在 Visual Studio 下添加 cryptlib.lib 的屏幕截图.请注意,它适用于所有配置:

Here's a screen capture of adding cryptlib.lib under Visual Studio. Notice it applies to all configurations:

这里是如何更改链接器路径以便 Visual Studio 找到正确的 cryptlib.lib:

And here's how to change the linker paths so Visual Studio finds the proper cryptlib.lib:

在上面,CRYPTOPP_LIB32 将是一个环境变量,其值类似于 C:\Users\Special Services\Crypto++\Win32\.类似地,CRYPTOPP_LIB64 将是 C:\Users\Special Services\Crypto++\x64\

In the above, CRYPTOPP_LIB32 would be an environmental variable with a value like C:\Users\Special Services\Crypto++\Win32\. Similarly, CRYPTOPP_LIB64 would be C:\Users\Special Services\Crypto++\x64\

很遗憾,我不知道如何在 QtCreator 下做这些事情.

Unfortunately, I don't know how to do these things under QtCreator.

这篇关于如何将 Crypto++ 库添加到 Qt 项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆