A question about how to handle the library compatibility issue

I want to use the function setenv and unsetenv in my application, but I found the couple of functions only be implemented in the libc.so.1 on solaris10. ( I did not find the implementation in libc.so.1 on solaris9)

Currently, I must use the above functions both in solaris9 and solaris10, so I decided to write a private one for solaris9 and put it into my shared library mylib.so. But I could not compile them for both solaris9 and solaris10. So I have to use a macro (MACRO_XX) to distinguish which platform I should compile the private functions setenv and unsetenv into mylib.so.

#if defined(MACRO_XX)

setenv ()

{

}

unsetenv()

{

}

#endif

The problem is I don抰 know what the macro MACRO_XX should be, the OS level (according to run-time OS), Compiler version, or something else? Which one is better?

Any responses are welcome. Thanks very much.

[920 byte] By [Daniceexia] at [2007-11-27 9:23:31]
# 1

Why don't you use getenv/putenv which are defined in both solaris 9 and 10.

Alternatively functions in your libraries should overide the ones in system libraries, so in theory you should be able to compile your in solaris 10 as well...

I suppose it might clash with headers, so you could define "my_setenv" I suppose. Or just make sure you match the header definition..

robert.cohena at 2007-7-12 22:18:44 > top of Java-index,Solaris Operating System,Solaris Essentials - General Technical Questions...
# 2

Thanks for your response.

It just because I still need to use setenv and unsetenv in linux platform ( and it looks like the getenv/putenv could unset the variables), so I have to use it.

And I think I'd better use the system supplied one if it has.

So, could you give me some advice about how to distinguish the library version compatibility issue commonly?

Daniceexia at 2007-7-12 22:18:44 > top of Java-index,Solaris Operating System,Solaris Essentials - General Technical Questions...
# 3

getenv/putenv are also defined on linux...

They are the standard interface that is the most widely supported.

Why do you think they would unset the variables.

If you really want to deal with OS version compatibility, the normal way to deal with this is by wrapping the compilation in an "autoconf" style system.

As far as I am aware theres no easy from the compiler to tell what system your on with any reliability.

So you would be best to write a shell script which tests the output of things like "uname" and sets environment variables that your makefile can pass to the compiler.

Or take the plunge and learn how to use autoconf.

robert.cohena at 2007-7-12 22:18:44 > top of Java-index,Solaris Operating System,Solaris Essentials - General Technical Questions...