2016-05-22 15 views
4

私はDebianマシン上にあり、私のラズベリーパイ2のプロジェクトをコンパイルしたいと思っています。私は単純なこんにちはの世界のためにそれをやってみましたが、錆びた木箱をどのようにクロスコンパイルするかを理解する。ラズベリーパイ2のクロスコンパイルサビ - openssl

arm-linux-gnueabihf-gccでopensslをコンパイルし、home/opensslArmディレクトリにインストールしました。

私は

OPENSSL_LIB_DIR=/home/johann/opensslArm/lib OPENSSL_INCLUDE_DIR=/home/johann/opensslArm/include cargo build --target=armv7-unknown-linux-gnueabihf 

を実行すると、私はこのエラーを取得:

failed to run custom build command for `openssl-sys-extras v0.7.11` 
Process didn't exit successfully: `/home/johann/projects/test/target/debug/build/openssl-sys-extras-e1c84960cd35bc93/build-script-build` (exit code: 101) 
--- stdout 
TARGET = Some("armv7-unknown-linux-gnueabihf") 
OPT_LEVEL = Some("0") 
PROFILE = Some("debug") 
TARGET = Some("armv7-unknown-linux-gnueabihf") 
debug=true opt-level=0 
HOST = Some("x86_64-unknown-linux-gnu") 
TARGET = Some("armv7-unknown-linux-gnueabihf") 
TARGET = Some("armv7-unknown-linux-gnueabihf") 
HOST = Some("x86_64-unknown-linux-gnu") 
CC_armv7-unknown-linux-gnueabihf = None 
CC_armv7_unknown_linux_gnueabihf = None 
TARGET_CC = None 
CC = None 
HOST = Some("x86_64-unknown-linux-gnu") 
TARGET = Some("armv7-unknown-linux-gnueabihf") 
HOST = Some("x86_64-unknown-linux-gnu") 
CFLAGS_armv7-unknown-linux-gnueabihf = None 
CFLAGS_armv7_unknown_linux_gnueabihf = None 
TARGET_CFLAGS = None 
CFLAGS = None 
running: "arm-linux-gnueabihf-gcc" "-O0" "-ffunction-sections" "-fdata-sections" "-g" "-fPIC" "-march=armv7-a" "-o" "/home/johann/projects/test/target/armv7-unknown-linux-gnueabihf/debug/build/openssl-sys-extras-e1c84960cd35bc93/out/src/openssl_shim.o" "-c" "src/openssl_shim.c" 
ExitStatus(ExitStatus(256)) 


command did not execute successfully, got: exit code: 1 



--- stderr 
In file included from src/openssl_shim.c:1:0: 
/usr/include/openssl/hmac.h:61:34: fatal error: openssl/opensslconf.h: No such file or directory 
compilation terminated. 
thread '<main>' panicked at 'explicit panic', /home/johann/.cargo/registry/src/github.com-88ac128001ac3a9a/gcc-0.3.28/src/lib.rs:840 
note: Run with `RUST_BACKTRACE=1` for a backtrace. 

私は疑問に変数をエクスポートする場合、私は同じエラーを取得します。

私は何をすべきか分かりません。私はクロスコンパイルの専門家ではありません。誰もこれを行うことができましたか?

EDIT:私はrust-openssl 0.7.11を使用していました。 0.7.13へのアップグレードは、この問題を修正(私は今、貨物がエラーなしで錆-opensslの依存関係をコンパイル見ることができる)が、私は今、別のものを持っている:

error: linking with `arm-linux-gnueabihf-gcc` failed: exit code: 1 
... 

note: /usr/lib/gcc-cross/arm-linux-gnueabihf/5/../../../../arm-linux-gnueabihf/bin/ld: /home/johann/opensslArm/lib/libssl.a(s23_meth.o): relocation R_ARM_THM_MOVW_ABS_NC against `a local symbol' can not be used when making a shared object; recompile with -fPIC 
/home/johann/opensslArm/lib/libssl.a: error adding symbols: Bad value 

どのように私は-fPICフラグを追加することができますか? opensslArmを特定のフラグで再コンパイルすべきですか?

+0

を持つこと 'は/ usr /含める/ opensslの/ HMAC出力の.hは本当に疑わしいです。それはカスタムバージョンではなく、通常インストールされているOpenSSLバージョンです。 '#include" foo "'の代わりに '' #include ''(https://github.com/sfackler/rust-openssl/blob/875f4ccb39e3863c6592b6275e067bd7692031d7/openssl-sys-extras/src/openssl_shim.c #L1-L4)は問題を引き起こすでしょう... – Shepmaster

+0

コメントありがとう!私はrust-opensslをクローンしてopenssl-sys-extraを手作業でコンパイルしようとしました。だから私は 'cargo update'を行いました。rust-opensslは0.7.11から0.7.13にアップグレードされましたが、現在は' arm-linux-gnueabihf-gcc'とのリンクに失敗しました。エラー – tafia

答えて

4

opensslコンパイルを設定するときにsharedオプションを渡す必要があります(これにより、-fPICパラメータがコンパイラに渡されます)。ここで

私はopensslのバージョンを印刷し錆のプログラムをコンパイルし、クロスをテストするために使用されるコマンドのシーケンスです:ホストコンピュータ上の

cd /tmp 

wget https://www.openssl.org/source/openssl-1.0.1t.tar.gz 
tar xzf openssl-1.0.1t.tar.gz 
export MACHINE=armv7 
export ARCH=arm 
export CC=arm-linux-gnueabihf-gcc 
cd openssl-1.0.1t && ./config shared && make && cd - 

export OPENSSL_LIB_DIR=/tmp/openssl-1.0.1t/ 
export OPENSSL_INCLUDE_DIR=/tmp/openssl-1.0.1t/include 
cargo new xx --bin 
cd xx 
mkdir .cargo 
cat > .cargo/config << EOF 
[target.armv7-unknown-linux-gnueabihf] 
linker = "arm-linux-gnueabihf-gcc" 
EOF 

cat > src/main.rs << EOF 
extern crate openssl; 

fn main() { 
    println!("{}", openssl::version::version()) 
} 
EOF 

cargo add openssl # requires cargo install cargo-add 
cargo build --target armv7-unknown-linux-gnueabihf 

テストコンパイルされたプログラム

SettingOPENSSL_STATICますrust-opensslは静的にリンクされています。あなたがrust-opensslの静的リンクされたバージョンを使用している場合は、armhf(crossbuild-essential-armhfon Debian)とqemu-staticのためのlibcをインストールするには、コマンドでコンパイルされたプログラムを実行することができます。

qemu-arm-static target/armv7-unknown-linux-gnueabihf/debug/xx 
+0

詳細な回答ありがとうございます。家に帰るとすぐに試してみるよ。 – tafia

関連する問題