web jni 遇到的问题(ubantu)

1、gcc: error trying to exec 'cc1plus': execvp: 没有那个文件或目录

apt-get install g++


2、java.lang.IllegalStateException: Web app root system property already set to different value

(http://www.cnblogs.com/ShaolinRong/archive/2013/02/27/2935080.html)

在web.xml中添加如下内容:

<!--如果不定义webAppRootKey参数,那么webAppRootKey就是缺省的"webapp.root"。但最好设置,以免项目之间的名称冲突。

定义以后,在Web Container启动时将把ROOT的绝对路径写到系统变量里。

<context-param>
<param-name>webAppRootKey</param-name>
<param-value>webName.root</param-value>
</context-param>

3、jni.h: no such file or directory

(http://stackoverflow.com/questions/13466777/jni-h-no-such-file-or-directory)

You have to add the JDK path to the include path, so the compiler knows the location of the file.

Windows:

/I "$(JAVA_HOME)\include" /I "$(JAVA_HOME)\include\win32"

Linux:

-I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux

-Idir  
  在你是用#include"file"的时候,gcc/g++会先在当前目录查找你所制定的头文件,如果没有找到,他回到缺省的头文件目录找,如果使用-I制定了目录,他    回先在你所制定的目录查找,然后再按常规的顺序去找.  对于#include<file>,gcc/g++会到-I制定的目录查找,查找不到,然后将到系统的缺  省的头文件目录查找.


4、javah 找不到类文件、找不到jni.h(ubuntu)

(http://blog.csdn.net/cghs123/article/details/7044826)

(http://blog.sina.com.cn/s/blog_54f82cc20101153x.html)

(http://blog.sina.com.cn/s/blog_54f82cc201011op1.html)


javah -classpath build/classes -d jni com.rose.controllers.TestJni

@saga-virtual-machine:~/data/RD/workspace_jee64/webjni_1/jni# gcc -I$JAVA_HOME/include -I$JAVA_HOME/include/linux -fPIC -shared testjni.c -o libtestjni.so


gcc -shared -fPIC -o 1.so 1.c
这里有一个-fPIC参数
PIC就是position independent code
PIC使.so文件的代码段变为真正意义上的共享!


gcc手册

-shared 
Produce a shared object which can then be linked with other objects to form
an executable. Not all systems support this option. 
(产生一个可以被其他obj链接生成可执行文件的共享obj。并非所有的系统都支持此选项)
For predictable results,
you must also specify the same set of options that were used to generate code
(‘-fpic’, ‘-fPIC’, or model suboptions) when you specify this option.1

-Idir  
  在你是用#include"file"的时候,gcc/g++会先在当前目录查找你所制定的头文件,如 果没有找到,他回到缺省的头文件目录找,如果使用-I制定了目录,他    回先在你所制定的目录查找,然后再按常规的顺序去找.   对于#include<file>,gcc/g++会到-I制定的目录查找,查找不到,然后将到系统的缺  省的头文件目录查找.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值