将Crypto ++ .lib文件添加到Qt项目 [英] Adding Crypto++ .lib file to Qt project

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

问题描述

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

  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

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



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



我相信我的理解,错误告诉我,我需要一个额外的行,其中所有的 else:win32 行在 DEPENDPATH ...或者是因为添加的行使用 $$ PWD ,不是Unix命令吗?我已经看过这个错误的其他情况下,我相当确定的问题是在.pro文件中的东西在这里。



编辑: / strong>



我决定采用不同的方法。我摆脱了任何导入库添加到我的.pro文件,而是只是把这行代码在其位置:



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



这个内置的很好。我确保所有的cryptopp头文件在我的include目录, C:\Qt\5.2.1\mingw48_32\include\cryptopp



然后我尝试包含一个文件, #include< cryptopp / aes.h> 我第一次建造,有40多个警告,但第二次建造,它建造没有任何。

解决方案


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



$ b b

在Visual Studio下的Windows上,Crypto ++库的名称是 cryptlib.lib ,而不是 libcryptlib.a 如果您使用的是Cygwin(我不认为你这样做),那么的名称 libcryptopp.a



libcryptlibd.a (注意添加 d )可能不正确。它代表'debug',它的东西在几年前在Visual Studio 5.0 / 6.0天使用。它基于将Crypto ++编译和集成到Microsoft Visual C ++环境如果 Win32 / Debug / cryptlib.lib 重命名为 Win32 / Debug / cryptlibd.lib



我认为现在推荐的做法是使用 cryptlib.lib 作为库(无处不在),并根据配置更改链接器路径。路径是:




  • Win32,Debug:< crypto ++ dir> / Win32 / Debug /

  • Win64,Debug:< crypto ++ dir> / x64 / Debug /

  • Win32,发布:< crypto ++ dir> / Win32 / Release /

  • Win64,发布:< crypto ++ dir> / x64 / Release /



$ c> cryptlib.lib 。注意它适用于所有配置:





下面是如何更改链接器路径,以便Visual Studio找到正确的 cryptlib.lib

>



在上面, CRYPTOPP_LIB32 是一个环境变量,值为 C:\Users\Special Services \Crypto ++ \Win32\ 。类似地, CRYPTOPP_LIB64 将是 C:\Users\ Specialecurity\Crypto ++ \x64\ p>

不幸的是,我不知道如何在QtCreator下做这些事情。


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: error: No rule to make target 'C:/Users/Special Services/WorkOrder/libcryptlibd.a', needed by 'debug\untitled.exe'. Stop.

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.

EDIT:

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 (The path to the cryptlib.lib file)

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

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

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.

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.

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, Debug: <crypto++ dir>/Win32/Debug/
  • Win64, Debug: <crypto++ dir>/x64/Debug/
  • Win32, Release: <crypto++ dir>/Win32/Release/
  • Win64, Release: <crypto++ dir>/x64/Release/

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

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

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\

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

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

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