Trouble to generate header file for JNI - java-native-interface

I compiled HelloWorld.c successfully. I changed to the directory where HelloWorld.class is.
And I typed javah -jni HelloWorld in Terminal to get header file. I have the following error message. What is the problem? I am developing Android app using Mac OSX.
error: cannot access HelloWorld
bad class file: ./HelloWorld.class
class file contains wrong class: Test.HelloWorld
Please remove or make sure it appears in the correct subdirectory of the classpath.
com.sun.tools.javac.util.Abort
javadoc: error - fatal error
2 errors

I guess that your HelloWorld.class is located in a subfolder Test. You are not expected to be INSIDE that folder but in the ROOT folder for your compiled package(s). So go out of that Test folder and try again javah -jni Test.HelloWorld
BTW i don't understand how you could "compile your HelloWorld.c succesfuly" if you don't even have the header yet. But i am answering what have been asked.

Related

Ran into a "'cl.exe' is not recognized" and "c1xx: fatal error C1083: Cannot open source file: No such file or directory" error

I encountered both of these errors when going through the Configure VS Code for Microsoft C++ article, here.
I had VS Code, got the C++ extension, used Developer Command Prompt(Run as Admin), made the right directories and projects using these commands:
mkdir projects
cd projects
mkdir helloworld
cd helloworld
code .
Which opened VS Code and I pasted in the helloworld code correctly and created the tasks.json file. But when I went running Build Task I got this error:
helloworld.cppc1xx: fatal error C1083: Cannot open source file:
'c:\Windows\System32\projects\helloworld\helloworld.cpp': No such file
or directory
And when I tried again today I got a completely different error:
'cl.exe' is not recognized as an internal or external command,operable
program or batch file.
I've tried looking for questions with similar errors to mine but none really seemed applicable. Any idea as to what I'm doing wrong?
You made your projects folder inside c:\Windows\System32\
This folder is accessible only with admin rights.
I am guessing that VS Code run build task without admin rights which causes the problem.
Try creating your projects folder in User folder.

fatal error C1083 : Cannot open include file: 'mexutils.h': No such file or directory

I would like to compile a c++ file as a mex file in MATLAB namely: "mexLasso.cpp".
These are the steps I take and I get the following error. What is the problem?
1. Put the files "mexLasso.cpp" and "mexutils.h" in a folder.
2. Set the compiler:
mex -setup C++
I recieve:
MEX configured to use 'Microsoft Visual C++ 2013 Professional' for C++ language compilation.
3. Run the command:
mex C:\...\mexLasso.cpp
I recieve the following error:
Error using mex
mexLasso.cpp
C:\...\mexLasso.cpp(33) : fatal error C1083: Cannot
open include file: 'mexutils.h': No such file or directory
Can somebody help us what we are missing?
From the mex command line tool reference, there is an argument for adding include paths:
-Ipathname Adds pathname to the list of folders to search for #include files.
Do not add a space between I and pathname.
Like this:
mex -v -IC:\path\to\mexutils_h\ mexLasso.cpp
Note that with -I you are not specifying the header, you are specifying a path containing one or more header files.
Thanks for your comments. I think the besy way to solve my problem is to install SPAMS in my machine and successfully compile it. I have posted the steps I take in this post :
How to install SPAMS toolbox in Matlab 2014b under windows 8.1
Can I have your opinion there. Sorry for duplicated message, only for relevancy and importance of the discussed topic.
Many thanks.

SpiderMonkey Link Error: FloatingPoint.h not found

I'm very new to spiderMonkey and have followed this tutorial to get started (I'm using MAC OS X): https://developer.mozilla.org/en/docs/How_to_embed_the_JavaScript_engine
Every time I try to do the linking command in Step 6:
cl helloworld.cpp -link dist/lib/mozjs185-1.0.lib
I get the following 2 problems:
1) mozjs185-1.0.lib is not present in any directory (I've downloaded both the spiderMonkey and Mozilla source code)
2) Once I edit the path to point to the .lib file I do have I get the following error: FloatingPoint.h not found. However, I can find FloatingPoint.h on the system just at a different directory.
Could anyone give me a clue as to in which directory these header files should be? Or how to get the required .lib file? I've followed instructions on the mozilla development site meticulously and still can't get a hang of this.
After a few hours battling with this, I've managed to link properly by adding the hello world.cpp file in the build-release folder (as described in the Build Documentation; for more info see: https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Build_Documentation).
From the terminal, I then cd into the build-release folder and type in the following command:
g++ -Idist/include -Ldist/bin -lmozjs185 helloworld.cpp -o helloworld
Unfortunately I am still getting this error:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/atomic:539:2: error: atomic is not implemented
I am pretty sure this has to do with the c++ compiler installed, and I still have to find a workaround, but at least it's properly linking now!

Javah error, cannot find class file

When I tried to use javah to generate header files, I get this error:
Error: Could not find class file for 'HelloWorld'.
Here is my External tools configuration.
Location: ${system_path:javah}
Working Directory: ${workspace_loc:/JniJava/bin/sonyraj}
Arguments: -jni HelloWorld
Try from the commnnd line/ terminal. maybe javah needs the full path to it? And without packages.
Or fully qualified package name as noted here Javah error while using it in JNI
javah -jni com.example.JavaHowTo
where com.example is your package.
You also need to run javah from the directory containing com/example/JavaHowTo.class
e.g. if your structure is
/home/user/project/Iot/com/example/JavaHotTo.class
run javah from
/home/user/project/Iot
I also had the same problem, try to put your .class files in a folder with the same name as the package name. Then run "javah packagename.ClassName". Hope it works for you too.

Jni Example in Eclipse

Hi while trying out jni example in this link http://wendro.blogspot.com/2010/03/jni-example-eclipse-dev-cpp.html?showComment=1309930446765#c5048550711511727724
with eclipse Helios windows xp am getting this error in eclipse console
"error: cannot access MyFirstWrapper,
class file for MyFirstWrapper not found,
javadoc: error - Class MyFirstWrapper not found.
Error: No classes were specified on the command line. Try -help."
what i have to do..???
Alternatively, set your run configuration's Working Directory to the project's bin. in the arguments, set flag -d to change where the output file goes to your cpp folder. For example:
Working Directory: ${workspace_loc:/ProjectRoot/bin}
Arguments: -d ${workspace_loc:/ProjectRoot/cpp} full.package.name.path.to.Class
Hi Thanks i only got the answer
i did like this i got a jni header file generated inside cpp folder
In Eclipse Run Tools, External Tools Configurations,
Name:Jni
Location:My javah.exe location
D:\ProgramFiles\Java\jdk1.6.0_17\bin\javah.exe
Working Directory: my javah file location
${workspace_loc:/jni_hello_world/cpp}
And the most important point is inside Arguments we have to give first as our .class location then jni command like below
-classpath E:\Workspace\JNI\jni_hello_world\bin
-jni MyFirstWrapper