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 6563077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:47:11+00:00 2026-05-25T13:47:11+00:00

Please help I search throw whole internet but I can’t find answer … C

  • 0

Please help I search throw whole internet but I can’t find answer …

C Layer

I have created simple function int mean(int, int); and place it in calc_mean.h and initialize it in calc_mean.c here are this two files.

calc_mean.c

#include "calc_mean.h"

int mean(int a, int b)  
{  
return (a+b) / 2;  
}  

calc_mean.h

int mean(int, int);

Then I create make file and build archive (.a) file called Test_Archive.a using following make file

makefile

GCC := C:\Tools\ndk-toolchain\ndk-standalone\bin\arm-linux-androideabi-gcc.exe
GPP := C:\Tools\ndk-toolchain\ndk-standalone\bin\arm-linux-androideabi-g++.exe
AR  := C:\Tools\ndk-toolchain\ndk-standalone\bin\arm-linux-androideabi-ar.exe

default: all

all: obj
    $(AR) r Test_Archive.a *.o

obj:
    $(GPP) -c *.c

I get Test_Archive.a archive file. Now I want to add this archive file to JNI and call mean function from my JNI project, for that I have created JNI and Java files which you can see below.


JAVA Layer

How you can see here in java layer I have TestJavaClass that have one native method called JMean this method have two int arguments and return also int.

public class TestJavaClass
{
    /** Default Constructor
     * 
     */
    public TestJavaClass( ) {

    }

    /** Test Function. 
     *  
     * @param a
     * @param b
     * @return
     */
    public native int JMean( int a, int b);
}

JNI Layer

This is JNI header file

Test_Library.h

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_Fido_OSTXLib_OSTX */

#ifndef _Included_com_Fido_OSTXLib_OSTX
#define _Included_com_Fido_OSTXLib_OSTX
#ifdef __cplusplus
extern "C" {
#endif

/*
 * Class:     com_Fido_OSTXLib_OSTX
 * Method:    JMean
 * Signature: (II)I
 */
JNIEXPORT jint JNICALL Java_com_Fido_OSTXLib_OSTX_JMean
  (JNIEnv *, jobject, jint, jint);

#ifdef __cplusplus
}
#endif
#endif

Test_Library.c

#include "Test_Library.h"
#include "calc_mean.h"

JNIEXPORT jint JNICALL Java_com_Fido_OSTXLib_OSTX_JMean( JNIEnv* env, jobject thiz, jint a, jint b )
{
    return mean( a, b );
}

I put this two files Test_Library.h, Test_Library.c and calc_mean.h, Test_Archive.a and create make file Android.mk

Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE           := Test_Library
LOCAL_SRC_FILES        := Test_Library.c

LOCAL_LDLIBS := -LTest_Archive.a

include $(BUILD_SHARED_LIBRARY)

but when I want to create .so file, the following error occurs, why ?

$ ../../ndk-build Compile thumb : Test_Library <= Test_Library.c
SharedLibrary : libTest_Library.so
C:/cygwin/home/android-ndk-r5b/Fido/ProjectOSTX/obj/local/armeabi/objs/OSTX_Library/OSTX_Library.o:
In function Java_com_Fido_OSTXLib_OSTX_JMean':
C:/cygwin/home/android-ndk-r5b/Fido/ProjectOSTX/jni/OSTX_Library.c:6:
undefined reference to
mean’ collect2: ld returned 1 exit status make: *
[/home/android-ndk-r5b/Fido/ProjectOSTX/obj/local/armeabi/libOSTX_Library.so]
Error 1

Why undefined reference to `mean’ ?

  • 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-05-25T13:47:12+00:00Added an answer on May 25, 2026 at 1:47 pm

    As I suppos the main reason was compiler settings, I make some modifications in makefile and my .a archive linked to shared library, here are modifications.

    GCC := C:\Tools\ndk-toolchain\ndk-standalone\bin\arm-linux-androideabi-gcc.exe
    GPP := C:\Tools\ndk-toolchain\ndk-standalone\bin\arm-linux-androideabi-g++.exe
    AR  := C:\Tools\ndk-toolchain\ndk-standalone\bin\arm-linux-androideabi-ar.exe
    
    OPTIONS  :=\
    -fpic \
    -ffunction-sections \
    -funwind-tables  \
    -fstack-protector \
    -D__ARM_ARCH_5__ \
    -D__ARM_ARCH_5T__ \
    -D__ARM_ARCH_5E__ \
    -D__ARM_ARCH_5TE__ \
    -Wno-psabi \
    -march=armv5te \
    -mtune=xscale \
    -msoft-float \
    -mthumb \
    -Os \
    -fomit-frame-pointer \
    -fno-strict-aliasing \
    -finline-limit=64 \
    -DANDROID \
    -Wa, \
    -O2 \
    -DNDEBUG \
    -g \
    
    default: all
    
    
    all: obj
        $(AR) r libtestlibrary.a *.o
    
    obj:
        $(GCC) $(OPTIONS) -c *.c
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written following regex But its not working. Can you please help me?
please help me with writing this search sql stored procedure procedure may have different
Please help me. How can I do for www.example.com/search.php?q=skipsoft to www.example.com/skipsoft?
Hi can someone please help me in writing this regex. I need to search
I did search but I could not find an answer; When interpreting android accelerometer
I have search for the topic mentioned above but I didn't find good satisfying
Please help! Background info I have a WPF application which accesses a SQL Server
i search lot in the internet and could not find any good tutorial about
Please help, I got the code below from a book but it doesnt seem
Can you please help me how to convert the following code to using "in"

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.