交叉编译 openssl , libssh2

要使用sftp功能,从网上找了QSsh-master代码在centos上编译,结果qt报错

../../QSsh-master/src/3rdparty/botan/botan.cpp:1127:43: error: impossible constraint in 'asm'

从网上找了没有找到解决办法。就改用libssh2来实现sftp功能在centos6.8上的交叉编译环上编译openssl,执行./configure 失败报错Can't locate IPC/Cmd.pm,百度了下

报错原因:缺少IPC/Cmd.pm模块

解决方法:

安装perl-CPAN,

yum install -y perl-CPAN

嫌弃安装软件麻烦,决定把交叉编译环境整到ubuntu 16 32位上。

新建虚拟机,装好系统 ,安装qt环境,编译一个嵌入式程序测试,报错找不到编译器,我设置了环境变量PATH,但就是报错,又百度,说编译其他平台程序 ,环境变量设置是修改/etc/environment文件,后加入后,终于可以编译了。

接着要交叉编译openssl , libssh2 两个

下载源码,先是编译openssl,

先apt-get install libssl-dev

否则报错configure: error: OpenSSL Crypto library not found

./Configure linux-armv4 --cross-compile-prefix=arm-hisiv400-linux- --prefix=/home/mission/sftp/openssl-3.0.1

第一个linux-armv4是嵌入式平台

--cross-compile-prefix是加上交叉编译的前缀,makefile则会自动变成arm-hisiv400-linux-g++等,

且产生的makefile也是能直接使用。

编译好后,再编译libssh2

./configure  CC=arm-hisiv400-linux-g++ --prefix=/home/mission/sftp/libssh2-1.10.0 指定编译器后,报错 

checking whether we are cross compiling... configure: error: in `/home/mission/sftp/libssh2-1.10.0/libssh2-1.10.0':
configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.

后改成./configure  CC=arm-hisiv400-linux-g++ --prefix=/home/mission/sftp/libssh2-1.10.0 --host=arm-linux

又报错

configure: ERROR: No openssl crypto library found!
No libgcrypt crypto library found!
No mbedtls crypto library found!
No wincng crypto library found!

Specify --with-crypto=$backend and/or the neccessary library search prefix.

Known crypto backends: auto, openssl, libgcrypt, mbedtls, wincng
configure: error: Required dependencies are missing!
又改./configure  CC=arm-hisiv400-linux-g++ --prefix=/home/mission/sftp/libssh2-1.10.0 --host=arm-linux --with-libssl-prefix=/home/mission/sftp/openssl-3.0.1

加上了自己编译的openssl的路径,终于好了。

但make时又报错。找不到libatomic.so,把交叉编译环境里的这个库找到放到openssl的库一起,再编译

/opt/hisi-linux/x86-arm/arm-hisiv400-linux/bin/../lib/gcc/arm-hisiv400-linux-gnueabi/4.8.3/../../../../arm-hisiv400-linux-gnueabi/bin/ld: warning: libssl.so.3, needed by ../src/.libs/libssh2.so, not found (try using -rpath or -rpath-link)
/opt/hisi-linux/x86-arm/arm-hisiv400-linux/bin/../lib/gcc/arm-hisiv400-linux-gnueabi/4.8.3/../../../../arm-hisiv400-linux-gnueabi/bin/ld: warning: libcrypto.so.3, needed by ../src/.libs/libssh2.so, not found (try using -rpath or -rpath-link)
../src/.libs/libssh2.so: undefined reference to `EVP_MD_CTX_free@OPENSSL_3.0.0'
../src/.libs/libssh2.so: undefined reference to `EVP_ripemd160@OPENSSL_3.0.0'
../src/.libs/libssh2.so: undefined reference to `EVP_PKEY_derive@OPENSSL_3.0.0'
../src/.libs/libssh2.so: undefined reference to `EVP_PKEY_get1_EC_KEY@OPENSSL_3.0.0'
../src/.libs/libssh2.so: undefined reference to `EVP_PKEY_get1_DSA@OPENSSL_3.0.0'
../src/.libs/libssh2.so: undefined reference to `BIO_ctrl@OPENSSL_3.0.0'
../src/.libs/libssh2.so: undefined reference to `EVP_PKEY_free@OPENSSL_3.0.0'
../src/.libs/libssh2.so: undefined reference to `RSA_get0_factors@OPENSSL_3.0.0'
../src/.libs/libssh2.so: undefined reference to `HMAC_Final@OPENSSL_3.0.0'
../src/.libs/libssh2.so: undefined reference to `EVP_PKEY_CTX_new_id@OPENSSL_3.0.0'
../src/.libs/libssh2.so: undefined reference to `EVP_sha256@OPENSSL_3.0.0'
../src/.libs/libssh2.so: undefined reference to `EVP_DigestSignInit@OPENSSL_3.0.0'
../src/.libs/libssh2.so: undefined reference to `ECDSA_SIG_set0@OPENSSL_3.0.0'
../src/.libs/libssh2.so: undefined reference to `EC_KEY_get0_public_key@OPENSSL_3.0.0'
../src/.libs/libssh2.so: undefined reference to `ENGINE_load_builtin_engines@OPENSSL_3.0.0'
../src/.libs/libssh2.so: undefined reference to `EC_KEY_free@OPENSSL_3.0.0'
../src/.libs/libssh2.so: undefined reference to `BN_mod_exp@OPENSSL_3.0.0'
../src/.libs/libssh2.so: undefined reference to `EC_KEY_new_by_curve_name@OPENSSL_3.0.0'
../src/.libs/libssh2.so: undefined reference to `EVP_PKEY_keygen_init@OPENSSL_3.0.0'
../src/.libs/libssh2.so: undefined reference to `EVP_PKEY_get_raw_private_key@OPENSSL_3.0.0'
../src/.libs/libssh2.so: undefined reference to `EVP_sha1@OPENSSL_3.0.0'
../src/.libs/libssh2.so: undefined reference to `ECDSA_SIG_free@OPENSSL_3.0.0'
../src/.libs/libssh2.so: undefined reference to `EVP_DigestInit@OPENSSL_3.0.0'
../src/.libs/libssh2.so: undefined reference to `RSA_size@OPENSSL_3.0.0'
../src/.libs/libssh2.so: undefined reference to `EVP_PKEY_derive_init@OPENSSL_3.0.0'

参考网上别人的应该是没有加上库路径

又改./configure  CC=arm-hisiv400-linux-gcc --prefix=/home/mission/sftp/libssh2-1.10.0 --host=arm-linux --with-libssl-prefix=/home/mission/sftp/openssl-3.0.1 LDFLAGS="-Wl,-rpath-link,/home/mission/sftp/openssl-3.0.1/lib",终于好了

你可能感兴趣的:(交叉编译,c++)