OpenSSL库中的链接错误 [英] Linking errors in OpenSSL library

查看:469
本文介绍了OpenSSL库中的链接错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用OpenSSL.library正在检测但出现如下错误:

I am using OpenSSL in my project.library is detecting but getting some errors like below:

Error:(23) undefined reference to 'RSA_generate_key'
Error:(44) undefined reference to 'AES_set_encrypt_key'
Error:(45) undefined reference to 'AES_encrypt'
Error:(49) undefined reference to 'AES_set_decrypt_key'
Error:(50) undefined reference to 'AES_decrypt'
Error:error: linker command failed with exit code 1 (use -v to see invocation)

我的简单cpp代码在这里

my simple cpp code is here

native-lib.cpp

native-lib.cpp

#include<jni.h>
#include <string>

#include <android/log.h>
#include <openssl/rsa.h>
#include <openssl/aes.h>


extern "C"
JNIEXPORT jstring  JNICALL
Java_com_manvish_bwssb_Activities_MainActivity_stringFromJNI(
        JNIEnv *env,
        jobject /* this */) {
    std::string hello = "Hello from C++";
    return env->NewStringUTF(hello.c_str());
}
#define nr_bits 2048

extern "C"
JNIEXPORT int JNICALL
  Java_com_manvish_bwssb_Activities_MainActivity_checkRSA(JNIEnv *env, jobject /* this */) {
    RSA *rsa = RSA_generate_key(nr_bits, 65537, NULL, NULL);
    return 0;
}

static const unsigned char key[] = {
        0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
        0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
};

extern "C"
void
Java_com_manvish_bwssb_Activities_MainActivity_checkAES(JNIEnv *env, jobject /* this */) {

    unsigned char text[] = "Kishan of Nanda";
    unsigned char out[80];
    unsigned char decout[80];

    AES_KEY wctx;

    AES_set_encrypt_key(key, 128, &wctx);
    AES_encrypt(text, out, &wctx);
    printf("encryp data = %s\n", out);
    __android_log_print(ANDROID_LOG_DEBUG, "Gajanand", "Encrypted data: %s\n", out);

    AES_set_decrypt_key(key, 128, &wctx);
    AES_decrypt(out, decout, &wctx);

    printf(" Decrypted o/p: %s \n", decout);
    __android_log_print(ANDROID_LOG_DEBUG, "Gajanand", "Decrypted data: %s\n", decout);
}

我的Android.mk文件在这里

and my Android.mk file is here

Android.mk

Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := myLibrary
LOCAL_SRC_FILES := native-lib.cpp
LOCAL_C_INCLUDES = $(LOCAL_PATH)/include
LOCAL_SRC_FILES +:= libcrypto.so
LOCAL_SRC_FILES +:= libssl.so
LOCAL_LDLIBS := -llog

include $(BUILD_SHARED_LIBRARY)

我在适当的文件夹中包含了适当的.so文件.我没有得到未定义参考错误的原因.请帮助我解决此问题.

I included appropriate .so files in appropriate folder. I am not getting reason behind the undefined reference error.please help me to solve this issue.

推荐答案

您的问题源于makefile中的这些行

Your problem stems from these lines in your makefile

LOCAL_SRC_FILES +:= libcrypto.so
LOCAL_SRC_FILES +:= libssl.so

源文件(简称SRC)由编译器使用.这将生成.a文件. 链接器使用.so文件和.a文件来生成可执行文件和.so文件.

Source (SRC for short) files are used by the compiler; which will generate .a files. .so files and .a files are used by the linker to generate executables and .so files.

我建议删除这两行,然后添加

I would suggest removing those 2 lines and then adding

LOCAL_LDLIBS := -llog -lssl -lcrypto

似乎不是完整的解决方案;但留下后人.

Seems to not be the complete solution; but leaving here for posterity.

这篇关于OpenSSL库中的链接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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