当将静态libssh2库编译为i386时,它总是返回x86_64库 [英] When compiling a static libssh2 library as i386 it always returns an x86_64 library

查看:72
本文介绍了当将静态libssh2库编译为i386时,它总是返回x86_64库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在已经花了几个小时从事这项工作,因此任何见识都会受到赞赏.

Been working on this for hours now so any insight would be greatly appreciated.

我正在尝试为OS X上的iPhone Simulator编译libssh2(我已经为设备成功编译了它).

I'm trying to compile libssh2 for the iPhone Simulator on OS X (I already have it compiled successfully for the device).

我正在使用以下环境变量和命令:

I'm using the following environment variables and commands:

export DEVROOT=/Developer/Platforms/iPhoneSimulator.platform/Developer 
export SDKROOT=$DEVROOT/SDKs/iPhoneSimulator3.0.sdk 
export CC=$DEVROOT/usr/bin/gcc-4.2 
export LD=$DEVROOT/usr/bin/ld 
export CPP=$DEVROOT/usr/bin/cpp-4.2 
export CXX=$DEVROOT/usr/bin/g++-4.2 
export AR=$DEVROOT/usr/bin/ar 
export AS=$DEVROOT/usr/bin/as 
export NM=$DEVROOT/usr/bin/nm 
export CXXCPP=$DEVROOT/usr/bin/cpp-4.2 
export RANLIB=$DEVROOT/usr/bin/ranlib 
export LDFLAGS="-arch i386 -pipe -no-cpp-precomp -isysroot $SDKROOT -L/Users/<USERNAME>/Desktop/Dev/iphonesimulator-os/lib"
export CFLAGS="-arch i386 -pipe -no-cpp-precomp -isysroot $SDKROOT -I/Users/<USERNAME>/Desktop/Dev/iphonesimulator-os/include"
export CXXFLAGS="-arch i386 -pipe -no-cpp-precomp -isysroot $SDKROOT -I/Users/<USERNAME>/Desktop/Dev/iphonesimulator-os/include/"
export CFLAGS=-m32
export CPPFLAGS=-m32

cd /Users/<USERNAME>/Desktop/Dev/src/gnupg-1.4.10
sudo ./configure --host=i386-apple-darwin --prefix=/Users/<USERNAME>/Desktop/Dev/iphonesimulator-os
sudo make
sudo make install

cd /Users/<USERNAME>/Desktop/Dev/src/libgpg-error-1.7
sudo ./configure --host=i386-apple-darwin --prefix=/Users/<USERNAME>/Desktop/Dev/iphonesimulator-os --enable-shared=no
sudo make
sudo make install

cd /Users/<USERNAME>/Desktop/Dev/src/libgcrypt-1.4.5
sudo ./configure --host=i386-apple-darwin --prefix=/Users/<USERNAME>/Desktop/Dev/iphonesimulator-os --enable-shared=no --with-gpg-error-prefix=/Users/<USERNAME>/Desktop/Dev/iphonesimulator-os --disable-asm
sudo make
sudo make install

sudo ./configure --host=i386-apple-darwin --prefix=/Users/<USERNAME>/Desktop/Dev/iphonesimulator-os --with-libgcrypt-prefix=/Users/<USERNAME>/Desktop/Dev/src/libgcrypt-1.4.5
cd /Users/<USERNAME>/Desktop/Dev/src/libssh2-1.2.7
sudo make
sudo make install

生成的dylib显示为x86_64,当尝试使用静态库.iPhone应用程序中的一个文件说libssh2.a时,该文件是为不受支持的文件格式构建的,该文件格式不是要链接的体系结构(i386).

The dylib that is produced shows as x86_64 and when trying to use the static library .a file in the iPhone app is says libssh2.a, file was built for unsupported file format which is not the architecture being linked (i386).

libgcrypt和其他所需的库都已编译,没有问题.

libgcrypt and the other required libraries have all compiled with no issue.

提前谢谢!

推荐答案

我几乎遇到了同样的问题.我正在编译libssh2,但是我正在使用openssl.要强制配置为以32位模式编译,您需要设置CFLAGS和CPPFLAGS.在运行configure之前,请在终端中输入以下命令:

I ran into pretty much this same problem. I was compiling libssh2, but I was using openssl with it. To force configure to compile in 32 bit mode you will need to set the CFLAGS and CPPFLAGS. Enter these commands in the terminal before you run configure:

export CFLAGS=-m32
export CPPFLAGS=-m32

在终端中运行./configure之前,需要设置CFLAGS和CPPFLAGS.

Before running ./configure in the Terminal, you need to set the CFLAGS and CPPFLAGS.

export CFLAGS = -m32

export CFLAGS=-m32

导出CPPFLAGS = -m32

export CPPFLAGS=-m32

要使用openssl来构建libssh2,请首先下载最新的 openssl libssh2 源文件.转到您下载并解压缩openssl的目录.在构建openssl二进制文件后,实际上执行了上述命令,但这似乎无关紧要.但是,在构建libssh2之前,它们是必需的.

To build libssh2 with openssl the way I did it first download the latest openssl and libssh2 source files from their respective sites. Go to the directory you downloaded and unzipped openssl to. I actually did the above commands after I built the openssl binaries and it didn't seem to matter. They were required before building libssh2 though.

./configure --prefix =/TARGET_DIRECTORY

./configure --prefix=/TARGET_DIRECTORY

制作

进行安装

之后,切换到您下载并解压缩libssh2的文件夹.使用以下命令对其进行配置和构建:

After that switch over to the folder where you downloaded and unzipped libssh2. Configure and build it with the following commands:

./configure --with-openssl --with-libssl-prefix =/OPENSSL_TARGET_DIRECTORY --prefix =/LIBSSH2_TARGET_DIRECTORY

./configure --with-openssl --with-libssl-prefix=/OPENSSL_TARGET_DIRECTORY --prefix=/LIBSSH2_TARGET_DIRECTORY

制作

进行安装

您可以在目标目录的"lib"文件夹中找到* .a文件,以导入到Xcode项目中.

You can find the *.a files to import into the Xcode project in the target directorys' "lib" folders.

我确定您已经知道,这仅适用于iPhone模拟器.您需要为手臂架构进行构建,才能在设备上使用此库.

As I'm sure you already know, this is only for the iPhone simulator. You'll need to build for the arm architecture to use this library on a device.

这篇关于当将静态libssh2库编译为i386时,它总是返回x86_64库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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