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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:02:10+00:00 2026-06-01T19:02:10+00:00

I’m attempting to compile a native JNI call using the SWIG %native function and

  • 0

I’m attempting to compile a native JNI call using the SWIG %native function and I’m getting the below exception for the header file. I’m including both the jdk-1.6.0_30/include and jdk-1.6.0_30/include/linux in the makefile below, Any ideas? I’m compiling on 32bit linux.

Sample.h:

JNIEXPORT jobject JNICALL Java_test_jni_GetData (JNIEnv *, jclass);

SWIG.i:

%module Sample
%{
   #include "Sample.h"
%}
%include "Sample.h"
%typemap(jstype) DeviceId getID "com.test.jni.DeviceId"
%typemap(jtype) DeviceId getID "com.test.jni.DeviceId"
%typemap(javaout) DeviceId getID { return $jnicall; }
%native(getID) DeviceId getID();

Exception:

[exec]Sample.h: Error: Syntax error in input(1).
[exec] make-3.79.1-p7: *** [sample_wrap.c] Error 1

Makefile (not complete file):

     PACKAGE_DIR = src/java/com/test/jni
     PACKAGE = com.test.jni
     INCLUDES = -I/user/java/jdk-1.6.0_30/include/linux \
                -I/user/java/jdk-1.6.0_30/include \
                -I/user/src/include #Sample.h resides here
     CFLAGS = -Wall -fpic $(INCLUDES) -O0 -g3
     SFLAGS = -java $(INCLUDES) -package $(PACKAGE) -outdir $(PACKAGE_DIR)
  • 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-01T19:02:12+00:00Added an answer on June 1, 2026 at 7:02 pm

    I think you’ve got this in the wrong order. You need to first write:

    %{
    JNIEXPORT jobject JNICALL Java_test_jni_GetData(JNIEnv *, jclass);
    %}
    

    so that when you write:

    %native (GetData) jobject GetData();
    

    a declaration of the function already exists in the wrapper code that SWIG will generate.


    You can’t %include Sample.h directly like that if it’s got native functions in it. The SWIG preprocessor doesn’t know what JNIEXPORT or JNICALL are – they look like syntax errors unless they’ve been given as a macro.

    I’d suggest putting the native functions in a separate header file which you then only #include, not %include that file.

    Failing that you have several options open though, hiding the native function from SWIG, e.g.:

    #ifndef SWIG
    JNIEXPORT jobject JNICALL Java_test_jni_GetData (JNIEnv *, jclass);
    #endif
    

    in the header file would work, or you could modify the interface file to make SWIG ignore JNIEXPORT and JNICALL:

    %module Sample
    %{
       #include "Sample.h"
    %}
    #define JNIEXPORT
    #define JNICALL
    %include "Sample.h"
    %typemap(jstype) DeviceId getID "com.test.jni.DeviceId"
    %typemap(jtype) DeviceId getID "com.test.jni.DeviceId"
    %typemap(javaout) DeviceId getID { return $jnicall; }
    %native(getID) DeviceId getID();
    

    Although in that case SWIG will try to wrap it as well as take the %native directive which probably isn’t what you want!

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to render a haml file in a javascript response like so:

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.