c++ - 尝试在 OS X 上为 32 位和 64 位编译 GNU 库

标签 c++ c macos gnu gnupg

在此先感谢您对此提供的任何帮助,我已经在网上搜索过,但无法让它正常工作。

我正在尝试在运行 OS X 10.9.4 的 Mac 上从源代码编译来自 GNU 的 libgcrypt 库。我需要编译成一个 32 位二进制文​​件,稍后我将使用 lipo 与 64 位二进制文​​件混合(我有 64 位部分在工作)。我试图能够从 32 位和 64 位程序中引用 libgcrypt 二进制文件。链接在这里:http://www.gnu.org/software/libgcrypt/

我抓到了一个未去皮的来源。

我使用了以下配置:

$ ./configure -host=i386-apple-darwin10.5.0 CFLAGS='-arch i386' LDFLAGS='-arch i386'

结果是:

    Libgcrypt v1.6.2 has been configured as follows:

    Platform:                  Darwin (i386-apple-darwin10.5.0)
    Hardware detection module: hwf-x86
    Enabled cipher algorithms: arcfour blowfish cast5 des aes twofish
                               serpent rfc2268 seed camellia idea salsa20
                               gost28147
    Enabled digest algorithms: crc gostr3411-94 md4 md5 rmd160 sha1
                               sha256 sha512 tiger whirlpool stribog

    Enabled kdf algorithms:    s2k pkdf2 scrypt
    Enabled pubkey algorithms: dsa elgamal rsa ecc
    Random number generator:   default
    Using linux capabilities:  no
    Try using Padlock crypto:  yes
    Try using AES-NI crypto:   yes
    Try using Intel PCLMUL:    yes
    Try using DRNG (RDRAND):   yes
    Try using Intel AVX:       yes
    Try using Intel AVX2:      yes
    Try using ARM NEON:        n/a

但是当我尝试制作(或 sudo make)时,砰!

Making all in src
/bin/sh ../libtool  --tag=CC   --mode=link gcc -I/opt/local/include -arch i386 -Wall  -arch i386 -o mpicalc mpicalc-mpicalc.o libgcrypt.la -L/opt/local/lib -lgpg-error  
libtool: link: gcc -I/opt/local/include -arch i386 -Wall -arch i386 -o .libs/mpicalc mpicalc-mpicalc.o  ./.libs/libgcrypt.dylib -L/opt/local/lib -lgpg-error
ld: warning: ignoring file /opt/local/lib/libgpg-error.dylib, file was built for x86_64 which is not the architecture being linked (i386): /opt/local/lib/libgpg-error.dylib
Undefined symbols for architecture i386:
  "_gpg_strerror", referenced from:
      _print_mpi in mpicalc-mpicalc.o
      _scan_mpi in mpicalc-mpicalc.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [mpicalc] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

也可能感兴趣:

$ g++ --version 配置为:--prefix=/Applications/Xcode.app/Contents/Developer/usr--with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM 版本 5.1 (clang-503.0.40)(基于 LLVM 3.4svn) 目标:x86_64-apple-darwin13.3.0 线程模型:posix

相关网页链接:

https://gmplib.org/list-archives/gmp-discuss/2010-September/004312.html

非常非常感谢您的帮助。

最佳答案

好的,我已经解决了这个问题,希望其他人会对此感兴趣。

上面的配置标志不太正确。正确的配置命令是(需要 -m32):

./configure -host=i386-apple-darwin CFLAGS='-arch i386 -m32' LDFLAGS='-arch i386 -m32'

这将正确编译。仅供引用,为了编译 32 位 libgcrypt 库,您需要 32 位版本的 libgpg-error。

编译这些库的 32 位版本后,我使用 lipo 混合 32 位和 64 位版本,以便 32 位程序和 64 位程序都可以访问这些库。

lipo -create ./libgcrypt.20.dylib/usr/local/lib/libgcrypt.20.dylib -output/tmp/libgcrypt.20.dylib

sudo mv/tmp/libgcrypt.20.dylib/usr/local/lib/libgcrypt.20.dylib

关于c++ - 尝试在 OS X 上为 32 位和 64 位编译 GNU 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25609729/

相关文章:

macos - org.apache.httpd : Already loaded

c++:在构造函数中将shared_ptr的 vector 初始化为不同的指针

c++ - 在 C 和 C++ 指针表示法中将星号放在哪里

c - 我怎么知道任何 h264 文件的持续时间?

c++ - 如何在 OSX 应用程序的标题栏中的 Qt 中添加全屏图标?

macos - 使用裸可执行文件创建 .pkg 安装程序

c++ - 有没有办法在 C++ 代码中调用 .jar 文件?

c++ - QGraphicsItem 仅通过 X 轴移动对象

从 C 中的文本文件复制所需的字符串

c - 本身具有依赖性的静态库上的 AC_SEARCH_LIBS?