Java AES算法和UNIX下OpenSSL之间的加解密(2)

CFLAGS=-g -c -Aa -Ae +DD64
APPLIBS=-L/opt/openssl/0.9.8/lib/hpux64 -lssl -lcrypto -L/usr/lib/hpux64
CC=cc
all: aes
.c.o:
        $(CC) $(CFLAGS) $*.c
aes:  aes.o
        $(CC) -o aes aes.o \
                $(APPLIBS) +DD64
clean:
        rm -f *.o

    aes.c源码我就不讲了,大家可以参照上面那个链接里面的,这里主要讲下makefile里面的注意点。
    makefile文件里如果没有-L/opt/openssl/0.9.8/lib/hpux64 -lssl -lcrypto则会抛出以下错误:

ld: Unsatisfied symbol "EVP_EncryptInit_ex" in file aes.o
ld: Unsatisfied symbol "EVP_DecryptInit_ex" in file aes.o
ld: Unsatisfied symbol "EVP_CIPHER_CTX_cleanup" in file aes.o
ld: Unsatisfied symbol "EVP_EncodeBlock" in file aes.o
ld: Unsatisfied symbol "EVP_CIPHER_CTX_init" in file aes.o
ld: Unsatisfied symbol "EVP_EncryptFinal_ex" in file aes.o
ld: Unsatisfied symbol "EVP_DecryptFinal_ex" in file aes.o
ld: Unsatisfied symbol "EVP_DecryptUpdate" in file aes.o
ld: Unsatisfied symbol "EVP_EncryptUpdate" in file aes.o
ld: Unsatisfied symbol "EVP_aes_128_ecb" in file aes.o
ld: Unsatisfied symbol "EVP_DecodeBlock" in file aes.o
11 errors.
*** Error exit code 1

这是由于没有链接到openssl库的原因,那么大家也就明白加上这句的缘由了。makefile中/opt/openssl/0.9.8/lib/hpux64这个路径是openssl安装后库的所在路径,路径下应该有 libcrypto.a libssl.a libcrypto.so libssl.so 这些库文件。

讲了这么多其实就是对makefile的编写不熟悉,希望一样遇到此问题的看到这篇文章后能够顺利解决问题。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/7be7e22c96e9147b2d442eaf0457d071.html