如何使用MinGW在Linux上构建Crypto ++库? [英] How to build Crypto++ library on Linux with MinGW?

查看:104
本文介绍了如何使用MinGW在Linux上构建Crypto ++库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将c ++项目从Visual Studio 2013移植到ubuntu上的netbeans.目标是Windows可执行文件,到目前为止,它无法使用mingw作为编译器从netbeans编译Windows exe文件.

该项目需要Crypto ++库,而我只有Visual Studio的.lib版本.要将库包含在netbeans中,我首先需要以.a格式构建Crypto ++库.

我不清楚该怎么做.Ive找到了有关如何使用mingw为linux构建库的信息,但没有找到有关mingw进行交叉编译的信息.提供的GNUmakefile不起作用.我是否应该使用Windows和mingw设置虚拟机并以这种方式编译库?或按照此处的建议使用qmake"hack" http://www.qtcentre.org/threads/28809-Compiling-amp-using-Crypto-with-mingw-version-of-Qt 吗?建议的最后一个不错的Crypto ++版本已经很旧了.这很令人困惑,比拥有所需的库更容易移植整个项目.我愿意接受任何建议.

tldr:如何在Linux上构建libcryptopp.a以交叉编译Windows exe项目

例如,如果我交叉编译某物,则/usr/i686-w64-mingw32/lib/文件夹中有Windows库,如libuser32.a.我需要使等价的libcryptopp.a ..对不起,如果不清楚.如果我只是使用答案中的步骤进行构建(以及在Wiki中进行构建),则最终得到一个libcryptopp.a文件,但我怀疑它仅适用于Linux,因为如果我将该库链接到.exe文件中的netbeans中,则会交叉编译,我结束每个人都有对cryptopp东西的未定义引用.路径正确,我怀疑需要用与交叉编译兼容的等效libcryptopp.a替换该库.

edit2:即时通讯正在尝试按照此处的答案进行操作,现在即时通讯卡在了这里.在此命令之后构建cryptopp.

  make CXX =/usr/bin/i686-w64-mingw32-gcc INCLUDES =-I/usr/i686-w64-mingw32/include" LIBS =-L/usr/i686-w64-mingw32/lib"CXXFLAGS ="-std = c ++ 0x 

它的很多变化我总是以这个错误结束

trap.h:26:25:致命错误:Windows.h:没有这样的文件或目录#包括

这让我觉得它使用正确的编译器来创建一个.a lib文件,用于与该lib交叉编译Windows .exe.但是我不明白现在缺少标题出现了什么..:(

此外,如果我尝试链接lib文件(与Visual Studio一起使用),则会遇到很多链接错误,即对cryptopp内容的未定义引用.

如果有人知道怎么做的话,我会提供象征性的啤酒(几美元的比特币).

解决方案

灵感来自 http://wiki.amule.org/wiki/Cross-compilation_for_windows_with_mingw :

  sudo apt-get install mingw-w64git clone https://github.com/weidai11/cryptoppcd cryptopp出口TARGET = i686-w64-mingw32CXX = $ TARGET-g ++ RANLIB = $ TARGET-ranlib AR = $ TARGET-ar LDLIBS = -lws2_32 make -f GNUmakefile 

im trying to port a c++ project from visual studio 2013 to netbeans on ubuntu. The target is a windows executable, so far im able to compile windows exe files from netbeans using mingw as compiler.

The project needs the Crypto++ library and i only have the .lib version for visual studio. To include the library in netbeans i first need to build the Crypto++ library in the .a format.

Its not clear to me how should i do that. Ive found informations on how to build the library for linux with mingw but not for cross compilation with mingw. The provided GNUmakefile does not work. Should i set up a vm with windows and mingw and compile the library that way? Or maybe use the qmake "hack" as suggested here http://www.qtcentre.org/threads/28809-Compiling-amp-using-Crypto-with-mingw-version-of-Qt ? The last good Crypto++ version suggested there is quite old. This is confusing, porting the whole project is easier than having the required library. Im open to any suggestion.

tldr: how to build libcryptopp.a on linux for the cross compilation of a windows exe project

edit: for example if i cross compile something there are windows libraries in the /usr/i686-w64-mingw32/lib/ folder like libuser32.a. i need to make the equivalend libcryptopp.a.. sorry if is a bit unclear. if i simply build using the steps in answer (and in the wiki) i end up with a libcryptopp.a file but i suspect is linux-only, cause if i link that library in netbeans in the .exe file im cross compiling i end up with undefined references to cryptopp stuff everywere. the paths are correct, i suspect the library needs to be replaced with the equivalent libcryptopp.a compatible with crosscompiling.

edit2: im trying to follow the answer down here, now im stuck here. after this command to build cryptopp.

    make CXX=/usr/bin/i686-w64-mingw32-gcc INCLUDES="-I /usr/i686-w64-mingw32/include" LIBS="-L /usr/i686-w64-mingw32/lib" CXXFLAGS="-std=c++0x"

and many variations of it i always end up with this error

trap.h:26:25: fatal error: Windows.h: No such file or directory # include

which makes me think its using the right compiler to make a .a lib file for cross compiling the windows .exe with the lib. however i dont understand whats going on now with the missing header..:(

Also if i try to link the lib file (used with visual studio) i get a lot of linking errors, undefined reference to cryptopp stuff.

ill offer a symbolic beer (a couple of $ of Bitcoins) if someone finds out how to do it.

解决方案

Inspired by http://wiki.amule.org/wiki/Cross-compilation_for_windows_with_mingw:

sudo apt-get install mingw-w64
git clone https://github.com/weidai11/cryptopp
cd cryptopp
export TARGET=i686-w64-mingw32
CXX=$TARGET-g++ RANLIB=$TARGET-ranlib AR=$TARGET-ar LDLIBS=-lws2_32 make -f GNUmakefile

这篇关于如何使用MinGW在Linux上构建Crypto ++库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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