麻烦编译JNI [英] Trouble with compiling JNI

查看:176
本文介绍了麻烦编译JNI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过引用已经用JNI生成的头文件实现了以下C代码:

I have the following C code implemented by referencing to a header file already generated with 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 I try to compile it (to generate the so 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

我得到这个错误:

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

如何解决这个问题?

How can I fix this issue?

推荐答案

您必须添加 -shared linker选项

you have to add the -shared linker option

首先创建目标文件:

First create the object file:

cc -c HelloWorld.c

然后创建这样的

cc -shared -o libHelloWorld.so HelloWorld.o

这篇关于麻烦编译JNI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆