how do i compile all this?
Hello folks,
So here's my problem, Im doing this project with a couple of friends, and im the java guy (theyre c++). Im trying to understand how it all works together. I've been through the hello world examples, and now i want to play with more than one c++ file. how do i link it all together?
I've got these files:
Sync.java, which calls upon the JNI and uses the cpp code -
publicclass Sync{
publicnativedouble match(String source, String candidate);
static
{
System.load("E:\\Uni\\Computer Sciences\\image-rec\\workspace\\sync\\sync.dll");
}
publicstaticvoid main (String args[]){
System.out.println("hello, im in here");
Sync sync =new Sync();
Double d = sync.match("hello","world");
System.out.println("double is " + d);
}
}
then the c files:
first, the javah generated code:
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class sync_Sync */
#ifndef _Included_Sync
#define _Included_Sync
#ifdef __cplusplus
extern"C"{
#endif
/*
* Class:sync_Sync
* Method:match
* Signature: (Ljava/lang/String;Ljava/lang/String;)D
*/
JNIEXPORT jdouble JNICALL Java_Sync_match
(JNIEnv *, jobject, jstring, jstring);
#ifdef __cplusplus
}
#endif
#endif
and now the two simple .cpp files:
Sync.cpp
#include"Sync.h"
#include"ColorMatcher.h"
JNIEXPORT jdouble JNICALL Java_Sync_match (JNIEnv *env, jobject, jstring, jstring)
//double Matcher::match(char *sourceImage, char *candidateImage)
{
ColorMatcher* colMatcher =new ColorMatcher();
return colMatcher->getMatch();
}
this one calls ColorMatcher. if i wasnt clear about it, what i dont understand is how to use jni for more than 1 cpp source file. so heres the second one:
#include"ColorMatcher.h"
double ColorMatcher::getMatch()
{
return 155.5;
}
Now, i know that im passing strings and not doing anything with them, but first help me to run this one and then ill move on to strings.
So what do i do with these?
do i need another specially formatted h fiole for ColorMatcher?
do i need to compile the 2 .cpp files into one .dll?
for my 1 file examples, i used command prompt, along these lines:
cl -Ic:\java\include -Ic:\java\include\win32
-MD -LD HelloWorld.c -FeHelloWorld.dll
Thanks for the help,
Yotam

