1.交叉编译
参考了:
http://hi.baidu.com/lihuanhai1943/blog/item/00ef57fa9ee3d1d6b58f31d0.html
我的makefile修改完如下:
#CC=gcc
CC=armv6zk-none-linux-gnueabi-gcc
CFLAG= -fPIC -DOPENSSL_PIC -DOPENSSL_THREADS-D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DL_ENDIAN -DTERMIO -O3-fomit-frame-pointer -Wall
DEPFLAG= -DOPENSSL_NO_CAMELLIA -DOPENSSL_NO_CAPIENG-DOPENSSL_NO_CMS -DOPENSSL_NO_GMP -DOPENSSL_NO_JPAKE -DOPENSSL_NO_MDC2-DOPENSSL_NO_RC5 -DOPENSSL_NO_RFC3779 -DOPENSSL_NO_SEED
PEX_LIBS=
EX_LIBS= -ldl
EXE_EXT=
ARFLAGS=
#AR=ar$(ARFLAGS) r
AR=armv6zk-none-linux-gnueabi-ar$(ARFLAGS) r
#ARD=ar$(ARFLAGS) d
ARD=armv6zk-none-linux-gnueabi-ar$(ARFLAGS) d
#RANLIB=/usr/bin/ranlib
RANLIB=armv6zk-none-linux-gnueabi-ranlib
编译命令:
./configno-asm shared --prefix=/usr/local/openssl
no-asm表示不编译部分汇编代码
--prefix=/home/stb/md5表示把编译后的库,配置工具等放到此目录。
编译后:
md5/
|-- bin
| |--c_rehash
| `--openssl
|-- include
| `--openssl
|-- lib
| |--engines
| |--fips_premain.c
| |--fips_premain.c.sha1
| |--libcrypto.a
| |--libcrypto.so -> libcrypto.so.0.9.8
| |--libcrypto.so.0.9.8
| |--libssl.a
| |--libssl.so -> libssl.so.0.9.8
| |--libssl.so.0.9.8
| `--pkgconfig
`-- ssl
|-- certs
|-- man
|-- misc
|--openssl.cnf
`--private
2.测试程序的编译:
测试参考了:
http://www.cnblogs.com/taobataoma/archive/2007/05/11/743257.html
如何编译参考了:
http://www.cnblogs.com/cy163/archive/2009/03/12/1409434.html
/*
Code snippet to calculate SHA1sum using openssl libs.
Copyright 2005 Junichi Uekawa, given to public domain.
$ gcc openssltest.c –lssl
$ ./a.out < ./a.out
eae8189278303caaa78f2d89e6a6ebeb7d37b554
$ sha1sum ./a.out
eae8189278303caaa78f2d89e6a6ebeb7d37b554 ./a.out
*/
#include
#include
main ()
{
SHA_CTX s;
int i, size;
char c[512];
unsigned char hash[20];
SHA1_Init(&s);
while ((size=read (0, c, 512)) > 0)
SHA1_Update(&s, c, size);
SHA1_Final(hash, &s);
for (i=0; i < 20; i++)
printf ("%.2x", (int)hash[i]);
printf ("\n");
}
编译命令
armv6zk-none-linux-gnueabi-gccssl_test.c -I /home/stb/md5/include/ -L/home/stb/md5/lib -lssl -lcrypto -ldl -oding.out
-I参数制定了头文件路径;
-L参数制定了链接库路径;
-lssl-lcrypto –ldl参数是如何确定的呢。上面的
http://www.cnblogs.com/cy163/archive/2009/03/12/1409434.html讲的比较详细。
[root@localhostpkgconfig]# cat libssl.pc
prefix=/home/stb/md5
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include
Name: OpenSSL
Description: Secure Sockets Layer and cryptographylibraries
Version: 0.9.8j
Requires:
Libs: -L${libdir} -lssl -lcrypto -ldl
Cflags: -I${includedir}
3.在arm11核的开发板上运行:
[target@work]#./ding.out
出现错误:
./ding.out: error while loading sharedlibraries: libssl.so.0.9.8: cannot open shared object file: No such file ordirectory
[target@work]#export
export HISTSIZE="1000"
export HOME="/root"
export HOSTNAME="decate"
export LD_LIBRARY_PATH="/usr/local/lib"
。。。。。。。
把libssl.so.0.9.8、libcrypto.so.0.9.8拷贝到/usr/local/lib,并执行:
ln-s libssl.so.0.9.8 libssl.so
ln-s libcrypto.so.0.9.8 libcrypto.so
再次执行:
[target@work]#./ding.out
输出:
ac6edbdcc88ca9d85b9448843f4cb0d17cf686b3
自此,移植初步完成。