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

  • Home
  • SEARCH
  • 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 8669299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:26:24+00:00 2026-06-12T18:26:24+00:00

Some one help me on this please. I am working on a simple app

  • 0

Some one help me on this please.

I am working on a simple app the does factorial on android, using ndk.

I want to have 2 .cpp files, one for class factorial, and one will be the main that invokes method from that class.
I don’t know how to deal with the header problem when it comes to build, please help.

#include "com_lan_factorial_FacLib.h"

JNIEXPORT jlong JNICALL Java_com_lan_factorial_FacLib_fac
  (JNIEnv *env, jclass clazz, jlong n)

{


    jlong result = (jLong) (fac(n));

    return result;
}

This code call fac method. this is Main.cpp

#include <stdio>
#include "com_lan_factorial_FacLib.h"

long fac(long n)
    {
        long f = 1;
        long i;
        for(i = 1; i <= n; i++)
        {
             f *= i;
        }
        return f;
    }
}

This class create fac method. This is fac.cpp

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_CFLAGS := -Wno-psabi
LOCAL_MODULE := libfac
LOCAL_SRC_FILES := fac.cpp
LOCAL_C_INCLUDES := $(LOCAL_PATH)
include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_CFLAGS := -Wno-psabi
LOCAL_MODULE := FacLib
LOCAL_SRC_FILES := Main.cpp 
LOCAL_STATIC_LIBRARIES := libfac
include $(BUILD_SHARED_LIBRARY)

The compile log is:

C:\Users\Lan\workspace\Factorial>..\..\temp\android\android-ndk-r8b\ndk-build
"Compile++ thumb : FacLib <= Main.cpp
jni/Main.cpp: In function 'jlong Java_com_lan_factorial_FacLib_fac(JNIEnv*, jclass, jlong)':
jni/Main.cpp:7:30: error: 'fac' was not declared in this scope
make: *** [obj/local/armeabi/objs/FacLib/Main.o] Error 1

Im not sure why fac is not declare

  • 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-12T18:26:25+00:00Added an answer on June 12, 2026 at 6:26 pm

    Is your second file really called com_lan_factorial_fac.cpp.callMain? The problem with it is that does not have a .cpp extension. Its extension is callMain. Rename to something that ends with .cpp, and edit your Anrdoid.mk to list both file names:

    LOCAL_SRC_FILES := com_lan_factorial_callMain.cpp some_other_file_name.cpp
    

    You can list all your files in one line, or you can split it up like this:

    LOCAL_SRC_FILES := com_lan_factorial_callMain.cpp \
        some_other_file_name.cpp
    

    The other error message is that the file com_lan_factorial_fac.h can’t be found. Does such a file exist?

    EDIT: your Android.mk is wrong. You are not building two libraries – you’re building one, from two source files. It should go like this:

    LOCAL_PATH:= $(call my-dir) 
    include $(CLEAR_VARS) 
    
    LOCAL_CFLAGS := -Wno-psabi 
    
    LOCAL_MODULE := libfac 
    
    LOCAL_SRC_FILES := fac.cpp Main.cpp
    
    include $(BUILD_STATIC_LIBRARY) 
    

    And in your Main.cpp, you should declare that a function called fac() exists, between the #include line and the Java_com_lan_factorial_FacLib_fac function:

    extern long fac(long n);
    

    Your compilation error message has to do with the lack of this line.

    The LOCAL_C_INCLUDES line is not generally necessary.

    By the way, the builtin C datatype long and jlong as defined by Android JNI are not the same. Better rewrite your fac() to work with jlong‘s.

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

Sidebar

Related Questions

Can any one please help me solve this. I am resizing some flash object/embed
this kind of emergency, so please, can someone help me... I'm using movingboxes plugin
can someone please help me. why does this return an error: Dim stuff As
We Really need some help on this one: We've Struggled with all the Apple
I want to know mobile number from android apps.I searched in here.some one give
This is for homework but please know that I have looked online for help
I'm working on university scheduling problem and using simple genetic algorithm for this. Actually
Please i need someone to help convert this query entity(c#) form. select * from
Im a beginner to css, please can someone help me get this element to
Could someone please help me to convert this String into a Map ... String

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.