简体   繁体   English

导出C局部变量:JNI运行时行为问题

[英]exporting C local variables : JNI run-time behavior issue

I want to export some static variables in C library (libA for instance) to use them from outside in other C file. 我想在C库(例如libA)中导出一些静态变量,以从其他C文件的外部使用它们。

I used to use extern keyword for the desktop application and it was working, however when I moved to JNI & Android, the extern keyword couldn't do the trick because when trying to build the *.so of the libA, regardless of my other C file (which uses the libA static variables), I got copiler error of "undefined reference" for all of the "extern variables" of libA. 我曾经在桌面应用程序中使用extern关键字,但它一直在工作,但是当我移至JNI和Android时, extern关键字无法解决问题,因为在尝试构建libA的* .so时,无论我使用的是什么。 C文件(使用力霸静态变量),我得到的“未定义的引用”为所有力霸的“外部变量”的copiler错误。

For that, I tried to link the C file when generating the *.so of the libA, but at run time, I noticed that the variables have different addresses which is not the normal result of the extern keyword. 为此,我尝试在生成libA的* .so时链接C文件,但是在运行时,我注意到变量具有不同的地址,这不是extern关键字的正常结果。 ( meaning that I'm manipulating different addresses <=> different variables instead of same address <=> "same variable"). (这意味着我要处理不同的地址<=>不同的变量,而不是相同的地址<=>“相同的变量”)。

So, is there a way to solve this issue ? 那么,有没有办法解决这个问题呢? maybe using memcpy or memset and if it's the proper way, please how to do that ? 也许使用memcpy或memset,如果这是正确的方法,请如何做?

Thanks in advance. 提前致谢。

BR BR

would setting up a environment variable in the JNI file help you out? 在JNI文件中设置环境变量可以为您提供帮助吗?

Eg: setenv("GLOBALVARIABLE", "ON", 1); 例如: setenv("GLOBALVARIABLE", "ON", 1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM