473,408 Members | 1,753 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Using cout in native function (JNI)

hi,

I always get an exception "java.lang.UnsatisfiedLinkError" when I use
"cout" in my native function.
It works
- when i use "printf"
- other C++ features

Here is an example of the native C code I have:
---
#include <jni.h>
#include "FirstNative.h"
#include <iostream>
using namespace std;

JNIEXPORT void JNICALL Java_FirstNative_display(JNIEnv *env, jobject
obj)
{
cout << "Hello world!\n";
return;
}
---

Am I missing anything?
Regards
Fareeda
Jul 17 '05 #1
4 5448
Sorry for my earlier incorrect message but I am not able to work with
ANY C++ functionality. [I just had tried to use classes which worked].
I get the exception when using any c++ functions.

Any clue?

PS: I did make sure to add "extern C" in the header file, as per the
other discussions foudn on this topic.

Regards
Jul 17 '05 #2
fareeda wrote:
Sorry for my earlier incorrect message but I am not able to work with
ANY C++ functionality. [I just had tried to use classes which worked].
I get the exception when using any c++ functions.

Any clue?

PS: I did make sure to add "extern C" in the header file, as per the
other discussions foudn on this topic.

I would start by verifying that you can make a stand-alone C++
executable (no JNI involved). After that, create a library (same kind
as used by JNI) and verify that you can make a C++ executable that uses
the library. Then verify that you can make a C executable that uses the
library. That should shake out any environmental issues.

HTH,
Ray

Jul 17 '05 #3


Also try moving #include <iosteam> to the top of the includes.
Occasionally they clash without causing compiler warnings.

fareeda wrote:
Sorry for my earlier incorrect message but I am not able to work with
ANY C++ functionality. [I just had tried to use classes which worked].
I get the exception when using any c++ functions.

Any clue?

PS: I did make sure to add "extern C" in the header file, as per the
other discussions foudn on this topic.

Regards


Jul 17 '05 #4
Thanks for the information. But the following finally hellped me:
Using compiler options "-lCrun -lCstd" during creation of the library.
Also, these options have to be added AT THE END (else it does not work :()

Thanks
Fareeda
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Psycho0190 | last post by:
Hello World ! I got some questions about the JNI and its usage with Microsoft Visual Studio. First question: I made an Win32 Application that starts a VM when clicking on a button. The first...
1
by: Mats Olsson | last post by:
I have a native process (written in c) which generates an unknown number of bytes (jpeg images), and I would like to find an efficient way of transferring these bytes from native to java, the end...
3
by: gohaku | last post by:
Hi everyone, I would like to know if it's possible to use python (libraries) in a Java Program. I do not want to use: Process proc = Runtime.getRuntime.exec(command) I am basically looking for...
25
by: rokia | last post by:
in a project, I use many,many stl such as stack,list,vctor etc. somewhere the vector's size is more than 2K. is this a efficient way?
5
by: Scott Chang | last post by:
Hi all, I copied a set of VC++ version 6 source code of the 'cppdll'(2 projects) from a website and put the cppdll.cpp, cppdll.def, cpp.h, (as the 1st project) and test.cpp (as the 2nd project)...
1
by: | last post by:
Hi all, I am writing a sendmail milter application in Java. The incoming mails will usually have image file as attachments. My application is currently able to extract the ImageFile and save it...
6
by: jthep | last post by:
Hi I'm trying to write a JNI for a linkedlist class I wrote in C++. Basically I have a header file with the class definition and a C++ file with the definition of the class member functions. I...
3
by: maboo59 | last post by:
Hello, I need to call a function from a java class(Example.java, not Javascript) from within .Net 2.0 and I don't know how to do it. Does anyone hava any suggestions? Thanks
3
by: dawray | last post by:
Hi, i'm having problems running the following program can someone please tell me where i'm going wrong? This is the error i got when running the program Exception in thread "main"...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.