在 64 位机器上进行 Crypto++ 32 位编译
Crypto++ 32bit compilation on a 64bit machine
我在 Ubuntu 64 位机器上使用 cryptopp
。我需要为 32 位编译库,但我不知道如何做。
我应该在 GNU Makefile 中做一些更改还是在调用 make
时使用可选参数?
您可以尝试使用 make CC='gcc -m32' CXX='g++ -m32'
构建它,但您可能需要几个 32 位库。
您还可以在 chroot
-ed 环境中设置 32 位分发版(使用 debootstrap
)并在其中构建您的 crypto++
。
gcc
和g++
有一个特定的选项强制在32 位模式下编译,它是-m32
。因此,如果您的应用程序的 Makefile 系统设置正确,您只需 运行 编译如下:
$> CXX='g++ -m32' make
应该够了。
Shall I make some change in the GNU Makefile or use an optional argument when calling make?
每个人的答案都应该适合您。迂腐地说,以下内容也适用于 Crypto++ 5.6.3 及更高版本。它被添加到 CXXFLAGS
因为它是一个编译器选项:
export CXXFLAGS="-DNDEBUG -g2 -O2 -m32"
make static dynamic cryptest.exe
...
# Run validation suite
./cryptest.exe v
# Run test vectors
./cryptest.exe tv all
Crypto++ 5.6.2 曾经使用以下内容(来自 5.6.2's GNUMakefile):
1 CXXFLAGS = -DNDEBUG -g -O2
2 # -O3 fails to link on Cygwin GCC version 4.5.3
3 # -fPIC is supported. Please report any breakage of -fPIC as a bug.
4 # CXXFLAGS += -fPIC
...
8 ARFLAGS = -cr # ar needs the dash on OpenBSD
9 RANLIB = ranlib
...
25 ifeq ($(CXX),gcc) # for some reason CXX is gcc on cygwin 1.1.4
26 CXX = g++
27 endif
...
注意它无条件地设置了 CXX
和 CXXFLAGS
。这让我和其他一些用户非常烦恼,所以这是当 Wei 将图书馆移交给社区时我们首先改变的事情之一。
Crypto++ 5.6.3 及更高版本改变了这一点。 makefile 尝试尊重用户提供的所有内容,包括 CXX
、CXXFLAGS
、AR
、ARFLAGS
等(来自 5.6.3's GNUMakefile):
1 # Base CXXFLAGS used if the user did not specify them
2 CXXFLAGS ?= -DNDEBUG -g2 -O2
...
14 AR ?= ar
15 ARFLAGS ?= -cr # ar needs the dash on OpenBSD
16 RANLIB ?= ranlib
...
49 # We honor ARFLAGS, but the "v" often option used by default causes a noisy make
50 ifeq ($(ARFLAGS),rv)
51 ARFLAGS = r
52 endif
...
如果您正在为嵌入式和移动平台执行交叉编译,则相同的原则适用于 GNUmakefile-cross
。
我在 Ubuntu 64 位机器上使用 cryptopp
。我需要为 32 位编译库,但我不知道如何做。
我应该在 GNU Makefile 中做一些更改还是在调用 make
时使用可选参数?
您可以尝试使用 make CC='gcc -m32' CXX='g++ -m32'
构建它,但您可能需要几个 32 位库。
您还可以在 chroot
-ed 环境中设置 32 位分发版(使用 debootstrap
)并在其中构建您的 crypto++
。
gcc
和g++
有一个特定的选项强制在32 位模式下编译,它是-m32
。因此,如果您的应用程序的 Makefile 系统设置正确,您只需 运行 编译如下:
$> CXX='g++ -m32' make
应该够了。
Shall I make some change in the GNU Makefile or use an optional argument when calling make?
每个人的答案都应该适合您。迂腐地说,以下内容也适用于 Crypto++ 5.6.3 及更高版本。它被添加到 CXXFLAGS
因为它是一个编译器选项:
export CXXFLAGS="-DNDEBUG -g2 -O2 -m32"
make static dynamic cryptest.exe
...
# Run validation suite
./cryptest.exe v
# Run test vectors
./cryptest.exe tv all
Crypto++ 5.6.2 曾经使用以下内容(来自 5.6.2's GNUMakefile):
1 CXXFLAGS = -DNDEBUG -g -O2
2 # -O3 fails to link on Cygwin GCC version 4.5.3
3 # -fPIC is supported. Please report any breakage of -fPIC as a bug.
4 # CXXFLAGS += -fPIC
...
8 ARFLAGS = -cr # ar needs the dash on OpenBSD
9 RANLIB = ranlib
...
25 ifeq ($(CXX),gcc) # for some reason CXX is gcc on cygwin 1.1.4
26 CXX = g++
27 endif
...
注意它无条件地设置了 CXX
和 CXXFLAGS
。这让我和其他一些用户非常烦恼,所以这是当 Wei 将图书馆移交给社区时我们首先改变的事情之一。
Crypto++ 5.6.3 及更高版本改变了这一点。 makefile 尝试尊重用户提供的所有内容,包括 CXX
、CXXFLAGS
、AR
、ARFLAGS
等(来自 5.6.3's GNUMakefile):
1 # Base CXXFLAGS used if the user did not specify them
2 CXXFLAGS ?= -DNDEBUG -g2 -O2
...
14 AR ?= ar
15 ARFLAGS ?= -cr # ar needs the dash on OpenBSD
16 RANLIB ?= ranlib
...
49 # We honor ARFLAGS, but the "v" often option used by default causes a noisy make
50 ifeq ($(ARFLAGS),rv)
51 ARFLAGS = r
52 endif
...
如果您正在为嵌入式和移动平台执行交叉编译,则相同的原则适用于 GNUmakefile-cross
。