By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,478 Members | 1,703 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,478 IT Pros & Developers. It's quick & easy.

error while compiling jni.h

P: n/a
Hi,

I am getting a very strange error

ubuntu:~/docs/jni/jniexamples/chap2/HelloWorld$ gcc
-I/usr/local/share/jdk1.5.0_05/include
-I/usr/local/share/jdk1.5.0_05/include/linux HelloWorld.c
/usr/lib/gcc/i486-linux-gnu/4.0.2/../../../../lib/crt1.o: In function
`_start':
.../sysdeps/i386/elf/start.S:115: undefined reference to `main'
collect2: ld returned 1 exit status

How can I fix it?

thank you very much,

Marcelo
Nov 22 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
send the code u were trying to compile ....

Nov 22 '05 #2

P: n/a

Marcelo wrote:
Hi,

I am getting a very strange error

ubuntu:~/docs/jni/jniexamples/chap2/HelloWorld$ gcc
-I/usr/local/share/jdk1.5.0_05/include
-I/usr/local/share/jdk1.5.0_05/include/linux HelloWorld.c
/usr/lib/gcc/i486-linux-gnu/4.0.2/../../../../lib/crt1.o: In function
`_start':
../sysdeps/i386/elf/start.S:115: undefined reference to `main'
collect2: ld returned 1 exit status

How can I fix it?


By writing a function called int main() or int main(int , char**)

Nov 22 '05 #3

P: n/a
HelloWorld.c is:

#include <jni.h>
#include <stdio.h>
#include "HelloWorld.h"

JNIEXPORT void JNICALL
Java_HelloWorld_print(JNIEnv *env, jobject obj)
{
printf("Hello World!\n");
return;
}

---HelloWorld.java ----------
class HelloWorld {
private native void print();
public static void main(String[] args) {
new HelloWorld().print();
}
static {
System.loadLibrary("HelloWorld");
}
}

This is a jni program from the Sun Tutorial.

thanks for your help,.

Marcelo
PS: the command
gcc -I/usr/local/share/jdk1.5.0_05/include
-I/usr/local/share/jdk1.5.0_05/include/linux HelloWorld.c

Nov 22 '05 #4

P: n/a
If iam not wrong the .cpp file should be compiled into a shared object
library/DLL. Next the java class using the native function should use
some standard calls to utilize the Shared Object/DLL.

No wonder youe code returns such an error.... how can it produce an
executable if it does not find main .. so compile it into a Shared
Object.

Nov 22 '05 #5

P: n/a
Sorry , i was typing ".cpp file" since this list was for cpp.But the
same explanation holds good for C also.

Nov 22 '05 #6

P: n/a
Sorry , i was typing ".cpp file" since this group was for cpp.But the
same explanation holds good for C also.

Nov 22 '05 #7

P: n/a
Procrastinx wrote:
If iam not wrong the .cpp file should be compiled into a shared object
library/DLL. Next the java class using the native function should use
some standard calls to utilize the Shared Object/DLL.

No wonder youe code returns such an error.... how can it produce an
executable if it does not find main .. so compile it into a Shared
Object.

great idea!!!

with the -shared option it works just fine

thanks alot

Marcelo
Nov 22 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.