Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8288901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:22:40+00:00 2026-06-08T12:22:40+00:00

I am very new to Android, compiling, and linking in general. I do not

  • 0

I am very new to Android, compiling, and linking in general. I do not know which details are important with my problem, so I will just tell you everything. If you see anything strange or incorrect, please let me know.

I built the libcrypto.so and libssl.so libraries in the Android-NDK. I wrote native code which uses a function in openssl.so (and openssl.so uses functions in libssl.so). The code compiles, however I receive an “undefined reference” error when linking:

./obj/local/armeabi/objs/pki_send/pki_send.o: In function `main':
/home/android/nativeserver/jni/pki_send.c:27: undefined reference to `RSA_generate_key'
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi/pki_send] Error 1

I searched on Google and found a person with the same problem as me, she is even calling the same function (except this person is not building for Android): http://ubuntuforums.org/showthread.php?t=1081028. I’ll quote the part of her post here that is relevant to my problem:

When I remove an argument [to the function which causes the “undefined reference”] the compiler says that there’s too few arguments and when I add an argument the compiler says there’s too many arguments, so it seems like there is “some” kind of reference to the correct function. There’s some linking going on wrongly perhaps?

I noticed this same behaviour. She solved her problem by compiling with the -lssl setting, which tells the compiler to use the openssl library. For me to do this, I changed the module in the Android.mk file from this:

LOCAL_LDLIBS += -ldl

to this:

LOCAL_LDLIBS += -lssl -lcrypto -ldl 

I included -lcrypto just to be safe, since libssl depends on libcrypto. Now when I run ndk-build, I receive the following error:

/home/android/android-ndk-r8/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld: cannot find -lssl
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi/pki_send] Error 1

This error shows that “ld” cannot find libssl.so. I have both libcrypto.so and libssl.so in my jni directory. I ideally wanted to find a way to add the jni directory to the search path of “ld”, but I could not figure this out. I attempted to solve this problem by adding libssl.so and libcrypto.so to the following directory: /android-ndk-r8/platforms/android-8/arch-arm/usr/lib (I believe that “ld” searches here for libraries). Once I did this, I ran ndk-build again and received an “undefined reference” error:

./obj/local/armeabi/objs/pki_send/pki_send.o: In function `main':
/home/android/nativeserver/jni/pki_send.c:27: undefined reference to `RSA_generate_key'
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi/pki_send] Error 1

From here, I am clueless as to how to proceed.

Just in case it is important, here is the code in my Android.mk file:

LOCAL_PATH := $(call my-dir)
APP_PLATFORM := android-8

include $(CLEAR_VARS)

LOCAL_MODULE    := crypto 
LOCAL_SRC_FILES := libcrypto.so 
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../include/

include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE    := ssl 
LOCAL_SRC_FILES := libssl.so 
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../include/

include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)

LOCAL_SRC_FILES := pki_send.c 
LOCAL_MODULE    := pki_send 
LOCAL_SHARED_LIBRARIES := ssl crypto 
LOCAL_LDLIBS += -lssl -lcrypto -ldl

LOCAL_MODULE_TAGS := optional

include $(BUILD_EXECUTABLE)

EDIT: Something I forgot to add: when I use functions in my native code in libcrypto.so, the code compiles and links fine. It seems that I can use any function in libcrypto.so. However, the function which gives me problems is in libssl.so. This may or may not be important.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:22:41+00:00Added an answer on June 8, 2026 at 12:22 pm

    I solved the problem. The function I was calling, “RSA_generate_key”, only exists in the deprecated version of libcrypto.so. I was using the newer version that uses “RSA_generate_key_ex”. I found this out by doing a readelf on libcrypto.so:

    $ ./arm-linux-androideabi-readelf -all ~/nativeserver/jni/libcrypto.so |grep RSA_generate
       679: 00089239   992 FUNC    GLOBAL DEFAULT    7 RSA_generate_key_ex
     10334: 00089239   992 FUNC    GLOBAL DEFAULT    7 RSA_generate_key_ex
    

    The reason why the program still compiled is because RSA_generate_key is in the header file of openssl/rsa.h even though the library does not have it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am very new to android and I am developing this app which allows
I'm very new to Android development and just started to study. What I'm trying
I'm very new to Android . I've used Java before but not for around
Am very new to Android programming, so sorry if this is a simple problem.
I'm very new to Android development (just started today), and also very new to
I am very new to Android application development. Just started Hello world android application
Ok so I am very new to android and I am just trying to
OK, I am very new to Android and C#. Just started today in fact.
Am very new to Android projects. Just i tried to work with TabHost controller
I'm very new to android, and programming in general. I've got an email receiver

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.