java - Trouble with compiling JNI -


i have following c code implemented referencing header file generated jni:

#include <jni.h> #include <stdio.h> #include "helloworld.h"  jniexport void jnicall  java_helloworld_print(jnienv *env, jobject obj) {      printf("hello world!\n");      return; } 

when try compile (to generate library) using:

cc -g -i/usr/lib/jvm/java-7-openjdk/include -i/usr/lib/jvm/java-7-openjdk/include/linux helloworld.c -o libhelloworld.so 

i got error:

/usr/lib/gcc/i686-linux-gnu/4.6.1/../../../i386-linux-gnu/crt1.o: in function `_start': (.text+0x18): undefined reference `main' collect2: ld returned 1 exit status 

how can fix issue?

you have add -shared linker option

first create object file:

cc -c helloworld.c 

then create so

cc -shared -o libhelloworld.so helloworld.o 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -