简体   繁体   中英

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.

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.

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. ( 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 ?

Thanks in advance.

BR

would setting up a environment variable in the JNI file help you out?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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