I created a logging library liblog.so
. I want to share a variable called File *rt_file
it's defined in lib_rt.h
and also this header inherited by log_rt.c,log_linux.c ==> liblog.so
,logd.c ==> logd
and also log_rt_client.c ==> log_rt_client
. Here i created a daemon logd
which puts(actually should) file pointer
rt_file
.
That's what i want to do.
Here liblog.so
is a dynamic libarary, logd
starts on boot up and it should set file pointer to rt_file
and log_rt_client
should get the file pointer and print some logs.
Problem comes to share the common variable rt_file
.
I tried other suggestions suggested in
stackoverflow [1]: first solution was to use extern
and complete the task. For my situation i though for [2] this. Rather than making a global variable put the variable to scoped file and use get
and set
functions to access the values.
but both options didn't worked for me let me Explain.
- I (Have to)compiled all the files
liblog.so
logd
andlog_rt_client
separately so, it was showing error whenlog_rt_client
had declaration ofrt_file
but not defined because it's defined inlogd
. which was not(can't) compiled withlog_rt_client
. Though all the files linked toliblog.so
- When i tried second options, results were unexpected,
logd
calls toliblog.so
set's and get's the file pointer but when i ranlog_rt_client
rt_file
doesn't had the expected pointer(File pointer). Means allocation forrt_file
for both are differen.
Can any one suggest me a solution. Hope this explains everything.