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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:22:46+00:00 2026-05-24T07:22:46+00:00

I have a C++ project with some .cpp and .h files. One of these

  • 0

I have a C++ project with some .cpp and .h files. One of these .cpp has a function with this signature:

int** verts(int L, int W, int l, int w)

I’d like to use this function in a Java project. Yes, I could rewrite it in Java, but it’s a very very articulated function. It would be great calling this function (and obtain a matrix of integers) from Java.

Any idea?
Please consider that I’m a Java programmer, I’m very noob in C++ 😛

  • 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-24T07:22:48+00:00Added an answer on May 24, 2026 at 7:22 am

    You can write a library which contains this function, and wraps it with
    a JNI wrapper, but it’s not trivial. The most important question is
    what the int** really represent, and how they are managed: whether and
    how you have to delete them, and how you want to represent them in Java.
    Just guessing, I suspect that the pointer points to an array of int*,
    each of which points to an array of int; this is a common
    representation for a two dimensional array in C (but not what we’d
    normally use in C++). As for whether and how to delete them, this
    should be documented by the library which defines verts. Given that,
    you’ll first have to declare the function as native in a Java class:

    class Verts
    {
        static {
            System.loadLibrary( "<i>libraryName</i>" );
        }
    
        private static Integer[] nativeVerts( int L, int W, int l, int w );
        public Integer[][] verts( int L, int W, int l, int w )
        {
            Integer[] tmp = nativeVerts( L, W, l, w );
            //  reshape tmp...
            return reshapedData;
        }
    }
    

    (I’ve preferred to return a flattened, single dimensional array, rather
    than an Integer[][]. It will make the C++ much simpler.)

    what you’ll have to do is write a function along the following lines:

    #include "jni.h"
    extern "C" JNIEXPORT jIntArray JNICALL Java_Verts_nativeVerts(
        JNIEnv* env,
        jclass,
        jint L,
        jint W,
        jint l,
        jint w)
    {
        int** results = verts( L, W, l, w );
        std::vector<int> tmp;
        //  Fill tmp with the flattened results.
        //  Then do whatever you have to do to clean up the int**.
        jintArray jResults = env->newIntArray( tmp.size() );
        env->SetIntArrayRegion( jResults, 0, tmp.size(), &tmp[0] );
        return jResults;
    }
    

    Except that the above also needs considerably more error checking.

    Finally, compile and link the above into a dll with the name you gave to
    the System.loadLibrary() function on the Java side. And make sure
    your environment is set up so that Java can find the dll (either through
    $LD_LIBRARY_PATH (Unix) or %path% (Windows), or by passing the path by
    means of -Djava.library.path=... on the Java command line).

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

Sidebar

Related Questions

I have a Project model and it has some text attributes, one is summary.
I´ve got one project, where all my .h and .cpp files are included. This
I have a project that requires some configuration files. I want to keep the
I have an OS design project with some subprojects, I would like to try
I have a project with 50+ .h files and 50+ .cpp files. I'm using
I have found some threads that explain why C++ separates .cpp and .h files
I'm working with a large library of files, and have one .cpp to compile.
I have two projects within one solution. Both projects contain some files that are
I have a little project with some jsp deployed on an Tomcat 5.5. Recently
Say I have some C++ project which builds an exe or dll file. The

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.