Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 345325

Summary: CDT fails to parse JNI code
Product: [Tools] CDT Reporter: Bryan Hunt <bhunt>
Component: cdt-parserAssignee: Project Inbox <cdt-parser-inbox>
Status: RESOLVED INVALID QA Contact: Markus Schorn <mschorn.eclipse>
Severity: normal    
Priority: P3 CC: cdtdoug, jansch1991, Knasher, malaperle, mr.sunny.narula, yevshif
Version: 8.0   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:
Attachments:
Description Flags
Proof of cdt error message none

Description Bryan Hunt CLA 2011-05-10 15:22:54 EDT
I'm using the latest drop of CDT in the Indigo repository with some JNI code and opening the .h and .c files gives me loads of generic "syntax error", "Type 'JNICALL' could not be resolved", etc.  If you create a new C project with the following header file, you will see the generic syntax error:

#include <jni.h>

JNIEXPORT void JNICALL foo();

you can even simplify the header to JNIEXPORT void foo(); and still get the syntax error.
Comment 1 Markus Schorn CLA 2011-05-11 08:01:24 EDT
Most likely the parser cannot resolve the included file. You need to configure the include search path in the project properties 'C/C++ General - Paths & Symbols'.
Comment 2 Bryan Hunt CLA 2011-05-11 10:46:52 EDT
I have the include path set.  If it's not set, I get an "Unresolved inclusion" on the #include.  When the path is set, the #include resolves, but the code has parse errors.
Comment 3 Marc-André Laperle CLA 2011-06-25 04:55:04 EDT
This code parses for me on Mac. Try reindexing the project maybe? And occasionally, when I open my workspace, my opened file will be full of syntax errors. I just close it and reopen then it's fine. Is it possible that the editor reconciles before the index is setup?
Comment 4 Markus Schorn CLA 2011-07-04 07:57:25 EDT
Please create a parser log for the test file ocntaining the syntax error. You can do that from the context menu of the file in the project explorer: 'Index - Create Parser Log'
Comment 5 Markus Schorn CLA 2011-08-19 08:21:07 EDT
No response from submitter.
Comment 6 John Horan CLA 2011-09-09 18:42:00 EDT
I had this same problem when I moved my project over to Linux.  As it turns out the problem is due to fact that java on linux splits the jni headers over two directories %JAVA_HOME%/include and %JAVA_HOME%/include/linux and jni.h references headers in the second folder.  The resolution is to just add the second folder to your includes.
Comment 7 jan schuerman CLA 2012-07-19 08:17:15 EDT
I am currently expiriencing this problem on windows i did not make a system switch
the specific errors are :
 
Method 'NewStringUTF' could not be resolved	com_example_myproject_MainActivity.c	/MyProject/jni	line 7	Semantic Error

Type 'JNICALL' could not be resolved	com_example_myproject_MainActivity.h	/MyProject/jni	line 15	Semantic Error

i originally also had the unresolved include on #include <jni.h> which i solved by adding the directories of the inlude folder of JDK in eclipse c/c++ preferences

any help would be greatly appreciated.

I have not tried reindexing because i am new to eclipse and have no idea how to do it or what it does

thanks,
Jan
Comment 8 jan schuerman CLA 2012-07-19 08:22:53 EDT
Method 'NewStringUTF' could not be resolved   
com_example_myproject_MainActivity.c    /MyProject/jni    line 7    Semantic
Error  

Edit: was fixed by changing my notation to c++ inside a cpp file(which wasnt so before)
Comment 9 jan schuerman CLA 2012-07-19 09:20:33 EDT
Solved

My tutorial neglected to mention some extra includes, apparently in their version of the ndk and eclipse these include can be added later

thanks anyhow
Comment 10 Sunny Narula CLA 2013-04-08 01:39:28 EDT
I found this bug while searching it does exist. Even after resolving the correct paths eclipse cdt shows an error on the jni method signature line reporting a general syntax error. Please reopen this bug.
Comment 11 Sunny Narula CLA 2013-04-08 01:44:38 EDT
Created attachment 229419 [details]
Proof of cdt error message
Comment 12 Marc-André Laperle CLA 2013-04-13 23:44:54 EDT
(In reply to comment #10)
> I found this bug while searching it does exist. Even after resolving the
> correct paths eclipse cdt shows an error on the jni method signature line
> reporting a general syntax error. Please reopen this bug.

I can't reproduce this. I'm running Mac OS X 10.8.3 and Eclipse 3.8.2 with CDT 8.1.2, java version "1.6.0_43". Could you describe your setup? Could you add a parser log? See Markus's comment 4.

I added this path to my includes to get it to resolve jni.h:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers/